7

I know it's possible to remove a status bar, however the frame shifts up by the height of the status bar if you set it to hidden. As such, the following code:

[UIApplication sharedApplication].statusBarHidden = YES;

is not sufficient for just hiding the text of the status bar. What I'm ultimately attempting to accomplish here is something similar to the Gmail app in which as the side-menu is displayed, the status bar text is hidden, and then once a selection is made the frame returns to normal with the status bar text displayed.

This question shows how to animate the hiding of the status bar but the result is that the entire window shifts up by the height of the status bar. I'm trying to avoid that from happening.

1
  • set "View controller-based status bar appearance" to NO in .plist and try with fade animation Dec 22, 2013 at 17:51

3 Answers 3

8

Objective-C version:

[AppDelegate instance].window.windowLevel = UIWindowLevelStatusBar;

Swift version:

AppDelegate().window!.windowLevel = UIWindowLevelStatusBar
2

This should do it. It's a bit of a hack, however:

NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72} length:9] encoding:NSASCIIStringEncoding];
id object = [UIApplication sharedApplication];
UIView *statusBar;
if ([object respondsToSelector:NSSelectorFromString(key)]) {
     statusBar = [object valueForKey:key];
}
[UIView animateWithDuration:0.3
                     animations:^{
                         statusBar.alpha = 0.0f; 
                     }
];
4
  • (unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72} ... why not just "statusBar" or whatever those ASCII chars are? Guessing it says status bar.. 0x74 = 0x73 + 1 and t = s + 1 Dec 22, 2013 at 20:09
  • 2
    Because this gets around Apple's checks.
    – runmad
    Dec 22, 2013 at 20:37
  • 3
    Terrible solution, whether it is getting around Apple's checks or not. What happens in iOS7.1? 7.2? 8.0?
    – Léo Natan
    Dec 23, 2013 at 4:59
  • 2
    You mean this solution is based on circumventing an Apple static analysis check for the string statusBar? Terrible solution! I down vote not because it's necessarily a wrong answer, but not future proof and I can't advocate it. Dec 23, 2013 at 9:44
1

Somehow applying the following code in my code result of nil while unwrapping optional

AppDelegate().window!.windowLevel = UIWindowLevelStatusBar

I have used the following to make status bar text hide :

UIApplication.shared.delegate?.window!!.windowLevel = UIWindowLevelStatusBar 

And to reset status bar to default and show the text :

UIApplication.shared.delegate?.window!!.windowLevel = UIWindowLevelNormal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.