Add UIView banner above status bar iOS 7

前端 未结 3 1497
你的背包
你的背包 2020-12-08 04:45

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 t

相关标签:
3条回答
  • 2020-12-08 05:19

    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];
    
    0 讨论(0)
  • 2020-12-08 05:33

    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.

    0 讨论(0)
  • 2020-12-08 05:37

    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
    
    } 
    
    0 讨论(0)
提交回复
热议问题