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

前端 未结 12 1749
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 19:04

When I am navigating back & forth between parent and child controllers in a master - detail navigation controller, i see a dark shadow on the right side of navigation ba

12条回答
  •  [愿得一人]
    2020-11-30 19:25

    It seems to happen with any bar (TabBar or ToolBar) that is translucent.
    So one way to fix it is to set the _tabBar.translucent = NO; (in my case). This prevents the undesired shadow under the top navigation bar while leaving the navigation bar translucent. Unfortunately the bottom bar is no longer translucent though.

    It can be set back to translucent but all this has to happen after the whole pushing animation is finished thus switching this property is well noticeable.

    In case, however the bottom bar also has to be translucent and I don't want the user to see the change I resolved it with 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 the viewDidAppear: I simply reverts that back:

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

    There is just a little change in the appearance especially but it's barely noticeable and it's way better than having the shadow under the navigation bar.

    Hope it'll help others to keep bars translucent until Apple fix this behaviour as bars ARE meant to be hidden in some cases unlike it was suggested in other posts especially for the UITabBar

提交回复
热议问题