Dark shadow on the navigation bar during segue transition after upgrading to Xcode 5.1 and iOS 7.1

When I move back and forth between the parent and child controllers in the navigation controller of the main part, I see a dark shadow on the right side of the navigation bar at the top. It started after upgrading to Xcode 5.1. It is sad and distracting. How can I get rid of it?

+65
objective-c uinavigationcontroller segue uinavigationbar
Mar 14 '14 at 18:40
source share
10 answers
self.navigationController.navigationBar.translucent = NO; 

fixed it

+38
Mar 18 '14 at 7:56
source share
 self.navigationController.view.backgroundColor = [UIColor whiteColor]; 

I solved this problem by setting the background color as a navigation controller.

+98
Aug 21 '14 at 8:27
source share

A non-amusing answer is perfect. To achieve the same result, in the Builder AND STILL KEEP TRANSLUCENCY interface, select the navigation controller and set the custom runtime attribute view.backgroundColor , as shown in the screenshot (in the Identity Inspector). Repeat for all navigation controllers that show this problem.

This whole problem seems to be due to the fact that the black color (or virtually no color) of the UINavigationController flows at the time of the creation of the CoreGraphics snapshots that it launches during the animation. Thus, setting the color white will prevent this.

Identity Inspector -> Custom Runtime Attributes

+30
Jul 31 '15 at 13:05
source share

This seems to be a bug that was introduced in iOS 7.1. In my case, this is caused by the UIToolbar located directly below the navigation bar. A dark shadow also appears in the translucent tab bar.

The shadow seems to be caused by the background for the UIToolbar. Now I use this workaround in the view controller with a toolbar that hides the background view of the toolbar during the transition:

 - (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; } } 

This is the code for [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 

I filed this radar: http://openradar.appspot.com/16418845

+4
Mar 25 '14 at 15:51
source share

This seems to be happening with any bar (TabBar or ToolBar) that is translucent.
Thus, one way to fix this is to set _tabBar.translucent = NO; (in my case). This prevents unwanted shadow under the top navigation bar, leaving a translucent navigation bar. Unfortunately, the bottom panel is no longer translucent.

It can be returned to translucent, but all this should happen after the completion of the entire animation of pressing, so this property is clearly visible.

In the case, however, the bottom panel should also be translucent, and I do not want the user to see the change that I allowed using the following:

 /* 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]; }]; 

Then in viewDidAppear: I just return back:

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

There is only a slight change in appearance, but it is barely noticeable, and it is better than having a shadow under the navigation bar.

I hope this helps others make the bars transparent until Apple fixes this behavior, as in some cases ARE bars should be hidden, unlike what was suggested in other posts, especially for UITabBar

+4
Aug 27 '14 at 7:02
source share

Here is my variation ... it requires much less code than that, and is more efficient. This is if you want a translucent navigation bar, and also want to fix this shadow problem.

In the original ViewController (built into the navigation controller) ...

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

and

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

The result is the same as what Tom does (visually, to the end user) and is easier to implement. Hope this helps ...

+3
Jul 21 '14 at 21:36
source share

Although this is not the same as the iOS implementation in stock, it is a good way to fix the problem:

 - (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; }]; } 

You will get a nice tab fade / fade animation. Add the code to the root directory of the UIViewController .

+1
Aug 08 '14 at 11:07
source share

The following also works and leaves a transparent navigation bar:

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

+1
Nov 10 '16 at 10:22
source share
 self.navigationController!.navigationBar.translucent = false; 

This works for me to place it inside a function where you click on the new ViewController

0
Apr 02 '16 at 19:40
source share

Or, if you use the interface builder, you can simply select the navigation bar from your navigation controller and uncheck the Transparent box between the style and barcode in the attribute inspector to get rid of this strange effect -

Inspector

-one
Mar 27 '15 at 11:44
source share



All Articles