Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 Fade status bar text in and out?

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.

like image 579
Nick ONeill Avatar asked Dec 22 '13 17:12

Nick ONeill


2 Answers

Objective-C version:

[AppDelegate instance].window.windowLevel = UIWindowLevelStatusBar;

Swift version:

AppDelegate().window!.windowLevel = UIWindowLevelStatusBar
like image 92
Rajesh Kumar Avatar answered Sep 21 '22 16:09

Rajesh Kumar


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; 
                     }
];
like image 40
runmad Avatar answered Sep 22 '22 16:09

runmad