ios7 UINavigationBar stops extending under status bar after a while

≡放荡痞女 提交于 2019-12-12 08:26:39

问题


First of all - this is NOT a question about navigation bar overlapping status bar (as many others). UINavigationBar (of my navigation controller) is perfectly aligned as I want.

The problem is with my navigation bar custom background.
Background image (or navigation bar itself) stops expending under status bar randomly (after few seconds after my application starts or when I present / dismiss modal navigation controllers over it). My custom image has proper dimensions for iOS (640x128px).

1. Initial look (desired - custom 640x128px background extends nicely under status bar):

2. After a while (flickers by itself):

What could cause such random flickering of UINavigationBar background image?

I use following code to configure my background:

    // Load resources for iOS 7 or later
    [[CustomNavigationBar appearance] setBackgroundImage:[self imageNamed:@"bg_top_ios7.png"] forBarMetrics:UIBarMetricsDefault];
    [[CustomNavigationBar appearance] setBackgroundImage:[self imageNamed:@"bg_top_ios7.png"] forBarMetrics:UIBarMetricsDefaultPrompt];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

My status bar settings in the Info.plist file:

I have also following settings in my UIViewController subclass init method (not sure if it matters):

-(id)init{
//DLog(@"BaseViewController init...");
    if (self = [super init]) {

        popToRoot = modal = NO;
        rootIndex = 0;
        indexInBottomNavigation = 0;
        [Crashlytics setObjectValue:@"init" forKey:NSStringFromClass([self class])];


        // iOS 7 adoptions:
        if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
            self.edgesForExtendedLayout = UIRectEdgeNone;

        if ([self respondsToSelector:@selector(extendedLayoutIncludesOpaqueBars)])
            self.extendedLayoutIncludesOpaqueBars = YES;

        if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
            self.automaticallyAdjustsScrollViewInsets = NO;


    }
    return self;
}

My view controllers are embedded in UINavigationController (which takes care of UINavigatioBbar positioning). I am also using ECSlidingViewController (reveal container) as a container for my navigation controllers but I am not sure if it matters.


回答1:


It turned out I was changing clipsToBounds = YES of navigation controller's navigation bar (somewhere in the app):

navigationController.navigationBar.clipsToBounds = YES;

In order for UINavigationBar to extend its background under status bar its clipsToBounds must be set to NO (which is the default). Make sure you do not mock around with it.

Solution simple as:

navigationController.navigationBar.clipsToBounds = NO;



来源:https://stackoverflow.com/questions/20991861/ios7-uinavigationbar-stops-extending-under-status-bar-after-a-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!