iOS 7 Fade status bar text in and out?

谁都会走 提交于 2019-12-21 11:03:15

问题


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:


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; 
                     }
];



回答3:


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


来源:https://stackoverflow.com/questions/20732061/ios-7-fade-status-bar-text-in-and-out

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