在升级到Xcode 5.1和iOS 7.1后,在转换过程中导航栏上的黑影

当我在主控细节导航控制器中在父控制器和子控制器之间来回导航时,导航栏右侧的顶部会出现黑影。 它在升级到Xcode 5.1后开始了。 它感觉粗糙和分心。 我怎样才能摆脱它?

self.navigationController.view.backgroundColor = [UIColor whiteColor]; 

我通过设置导航控制器视图的背景色来解决这个问题。

 self.navigationController.navigationBar.translucent = NO; 

修复

nonamelive的答案是完美的。 要在Interface Builder 和STILL KEEP TRANSLUCENCY中实现相同的function,请select导航控制器并设置用户定义的运行时属性view.backgroundColor ,如截图所示(在Identity Inspector中)。 重复所有显示此问题的导航控制器。

看来,这个问题的发生是因为在animation开始的时候,CoreGraphics对UINavigationController的黑色(或者实际上没有颜色)进行了快照。 所以,将其设置为白色将防止这种情况。

Identity Inspector  - >用户定义的运行时属性

这似乎是iOS 7.1中引入的一个错误。 在我的情况下,它是由直接放置在导航栏下方的UIToolbar引起的。 黑影也出现在半透明的标签栏中。

阴影似乎是由UIToolbar的背景视图引起的。 我现在在视图控制器中使用这个解决方法,在转换过程中隐藏工具栏的背景视图:

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIView *toolbarBackgroundView = [self.toolbar findViewRecursively:^BOOL(UIView *subview, BOOL *stop) { BOOL isToolbarBackgroundView = ([subview isKindOfClass:[UIImageView class]] && [NSStringFromClass(subview.class) isEqualToString:@"_UIToolbarBackground"]); if (isToolbarBackgroundView) { *stop = YES; } return (! isToolbarBackgroundView); }]; if (toolbarBackgroundView) { // fade toolbar background view back in [UIView animateWithDuration:0.1f animations:^{ toolbarBackgroundView.alpha = 1.0f; }]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; UIView *toolbarBackgroundView = [self.toolbar findViewRecursively:^BOOL(UIView *subview, BOOL *stop) { BOOL isToolbarBackgroundView = ([subview isKindOfClass:[UIImageView class]] && [NSStringFromClass(subview.class) isEqualToString:@"_UIToolbarBackground"]); if (isToolbarBackgroundView) { *stop = YES; } return (! isToolbarBackgroundView); }]; if (toolbarBackgroundView) { // hide toolbar background view toolbarBackgroundView.alpha = 0.0f; } } 

这是[UIView findViewRecursively:]的代码

 @interface UIView (FindSubview) - (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse; @end @implementation UIView (FindSubview) - (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse { for (UIView* subview in self.subviews) { BOOL stop = NO; if (recurse(subview, &stop)) { UIView* view = [subview findViewRecursively:recurse]; if (view) return view; } else if (stop) { return subview; } } return nil; } @end 

我提交了这个雷达: http : //openradar.appspot.com/16418845

它似乎与任何酒吧(TabBar或工具栏)是半透明的。
所以解决这个问题的一个方法是设置_tabBar.translucent = NO; (在我的情况)。 这样可以防止顶部导航栏下的不需要的阴影,同时使导航栏保持半透明。 不幸的是底部栏不再是半透明的。

它可以被设置成半透明的,但是在整个推动animation完成之后,所有这些都必须发生,因此切换这个属性是非常明显的。

如果底部栏也必须是半透明的,我不希望用户看到更改,我使用以下方法解决:

 /* create a simple quick animation of the bottom bar just before pushing the new controller */ [UIView animateWithDuration:0.1 animations:^{ _tabBar.barTintColor = [UIColor colorWithWhite:0.97254901960784 alpha:1.0]; // this is the closest color for my case _tabBar.translucent = NO; } completion:^(BOOL finished) { /* now when the animation that makes the bar not translucent is finished we can push the new controller the controller is instantiated before the animation code */ [self.navigationController pushViewController:controller animated:YES]; }]; 

然后在viewDidAppear:我简单回复:

 [UIView animateWithDuration:0.1 animations:^{ _tabBar.barTintColor = nil; _tabBar.translucent = YES; }]; 

外观上只有一点点改变,但几乎没有什么明显的变化,比导航栏下的阴影更好。

希望它会帮助别人保持半透明,直到苹果解决这个问题,因为在某些情况下,酒吧意味着隐藏起来,而不像在其他post中提到的那样,特别是对于UITabBar

这是我的变化…它需要比汤姆的答案less得多的代码,并且更高效。 这是如果你想要一个半透明的导航栏,也想修复这个阴影问题。

在源视图控制器(即embedded在导航控制器中)…

 - (void)viewDidAppear:(BOOL)animated { self.navigationController.navigationBar.translucent = YES; } 

  - (void)viewWillDisappear:(BOOL)animated { self.navigationController.navigationBar.translucent = NO; } 

其结果与Tom所做的一样(视觉上对最终用户而言)相同,并且更容易实现。 希望这可以帮助…

虽然它与iOS版本不一样,但这是修复问题的好方法:

 - (void)viewWillAppear:(BOOL)animated { [UIView animateWithDuration:0.35f animations:^{ self.tabBarController.tabBar.alpha = 1.0f; }]; } - (void)viewWillDisappear:(BOOL)animated { [UIView animateWithDuration:0.35f animations:^{ self.tabBarController.tabBar.alpha = 0.0f; }]; } 

你会得到一个很好的淡入/淡出标签栏的animation。 在根UIViewController添加代码。

 self.navigationController!.navigationBar.translucent = false; 

这适用于我把它放在你推新的ViewController的function

以下内容也可以工作,并使导航栏保持透明:

[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor whiteColor];

或者,如果您使用的是界面构build器,则可以从导航控制器中select“导航栏”,然后取消选中“属性”检查器中的“样式”和“条形色调”之间的半透明checkbox,以消除奇怪的效果 –

检查员