Iphone – ios7 UINavigationBar stops extending under status bar after a while

ios7iphonestatusbaruinavigationbaruinavigationcontroller

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):

enter image description here

2. After a while (flickers by itself):

enter image description here

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:

enter image description here

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.

Best Answer

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;

Related Topic