IOS9: UIWindow user interface disables status bar display

When I create the UIWindow user interface in iOS9, the window becomes visible on the screen, but the status bar suddenly disappears.

When the window becomes hidden, the status bar appears again.

Below, 2 screenshots of what I get on iOS9 with Xcode7 beta5.

Status bar when user window is hidden: Status bar with hidden user window

Status bar when custom window is displayed: Status bar when custom window is displayed (The whole screen moves up.)

This is the code I'm using (which worked well on iOS8):

#define DEBUG_SHOWENV_HEIGHT 20.0f @interface AppDelegate () @property (nonatomic) UIWindow* envWindow; @end -(UIWindow*)envWindow { if (_envWindow == nil) { // Create the window _envWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0.0f, self.window.frame.size.height, self.window.frame.size.width, DEBUG_SHOWENV_HEIGHT)]; _envWindow.rootViewController = [[UIViewController alloc] init]; // added since iOS9 to avoid the assertion _envWindow.userInteractionEnabled = NO; _envWindow.windowLevel = UIWindowLevelStatusBar; _envWindow.backgroundColor = [UIColor colorWithRed:0.243 green:0.471 blue:0.992 alpha:0.8]; // Make a label UILabel* labelEnv = [[UILabel alloc] initWithFrame:CGRectMake(8.0f, 0.0f, _envWindow.bounds.size.width - 16.0f, DEBUG_SHOWENV_HEIGHT)]; labelEnv.font = [UIFont boldSystemFontOfSize:12.0f]; labelEnv.textColor = [UIColor whiteColor]; labelEnv.text = @"DEVELOP ENVIRONMENT"; [_envWindow addSubview:labelEnv]; } return _envWindow; } // ==== in applicationDidBecomeActive // Show the window 2 seconds then hide it. [self.envWindow.layer removeAllAnimations]; self.envWindow.frame = CGRectMake(0.0f, self.window.frame.size.height, self.window.frame.size.width, DEBUG_SHOWENV_HEIGHT); self.envWindow.hidden = NO; [UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ self.envWindow.frame = CGRectMake(0.0f, self.window.frame.size.height - DEBUG_SHOWENV_HEIGHT, self.window.frame.size.width, DEBUG_SHOWENV_HEIGHT); } completion:^(BOOL finished) { if (finished) { [UIView animateWithDuration:0.25f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ self.envWindow.frame = CGRectMake(0.0f, self.window.frame.size.height, self.window.frame.size.width, DEBUG_SHOWENV_HEIGHT); } completion:^(BOOL finished) { if (finished) { self.envWindow.hidden = YES; } }]; } }]; 

I would be grateful for any help.

+7
ios ios9 statusbar uiwindow
source share
2 answers

solved. I needed to implement this method in the root view controller:

 - (BOOL)prefersStatusBarHidden { return NO; } 

For some reason, the root view controller in this UIWindow hid the status bar. (although it should return NO by default, usually)

So instead:

 _envWindow.rootViewController = [[UIViewController alloc] init]; // added since iOS9 to avoid the assertion 

I created my own view controller with prefersStatusBarHidden redefined.

+4
source share

String _envWindow.windowLevel = UIWindowLevelStatusBar; puts your window at the same level (z-ordering) as the status bar. I think you need UIWindowLevelNormal so that a status bar is displayed above it.

0
source share

All Articles