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

前端 未结 12 1756
爱一瞬间的悲伤
爱一瞬间的悲伤 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:15

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

    The shadow seems to be caused by the background view of the UIToolbar. I now use this workaround in the view controller with the toolbar that hides the toolbar's background view 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

提交回复
热议问题