Add UIView banner above status bar iOS 7

浪子不回头ぞ 提交于 2019-11-27 05:34:42

问题


I'm trying to add a banner above the status bar when receiving an in-app push notification. From what I've been reading, it seems like the only way to dynamically change the status bar style in iOS 7 is to set UIViewControllerBasedStatusBarAppearance to NO. This is not only really annoying to have to change all my different view controllers prefersStatusBarHidden to [UIApplication sharedApplication].statusBarHidden, but it also doesn't give the effect I'm looking for.

When the banner slides from the top, I still want the 20 pts of space that the status bar provides to stay, but the status bar content to disappear until after the banner slides back up. Is there a way to either do this or add a subview or window above the status bar?

Basically I'm looking to do this:


回答1:


Create a new window and add your banner view to that window. When you need to show the banner, you can set yourwindow.hidden = NO; You can further add animations to showing it and to dismiss it yourwindow.hidden = YES;.

The key here is is setting yourwindow.windowLevel = UIWindowLevelStatusBar+1;

That will make sure your banner view and the yourwindow always appear above the status bar.

Feel free to ask questions regarding any of the above.




回答2:


To put your view controller above status bar:

[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar+1];

To put your view controller behind status bar:

[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelNormal];



回答3:


Add UIView banner above status bar-Swift4

func showBannerView(bannerView:UIView){
     let window = UIApplication.shared.keyWindow!
    window.addSubview(bannerView)
    window.windowLevel = UIWindowLevelStatusBar+1
}
func removeBannerView(bannerView:UIView){
    bannerView.removeFromSuperview()
    let window = UIApplication.shared.keyWindow!
    window.windowLevel = UIWindowLevelStatusBar - 1

} 


来源:https://stackoverflow.com/questions/22241412/add-uiview-banner-above-status-bar-ios-7

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