Swift 3 - how to hide Status Bar when using Over Full Screen

三世轮回 提交于 2019-12-10 17:14:15

问题


I'm developing a swift app and I can't find how to hide Status Bar when I use Over Full Screen presentation on my modal.

However, I put this line of code in my Modal View Controller :

override var prefersStatusBarHidden: Bool {
    return true
}

And it is working if I create a segue which is not a modal, or if I create a segue which is a modal but not with Over Full Screen presentation.

I searched on internet how to fix it, and I found people who had the same problem but there had no solution.

Also, I can't change the color of my Status Bar when I'm using Over Full Screen option. I don't understand why? I think it's related.

Thanks for your help!


回答1:


To hide the status bar when doing an over full screen modal, you need to set this in viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()    
    modalPresentationCapturesStatusBarAppearance = true
}

Then do the standard method to hide the status bar:

override var prefersStatusBarHidden: Bool {
    return true
}



回答2:


We can override preferredStatusBarStyle from individual view controller as you have done correctly.

Along with this, insert a new key named “View controller-based status bar appearance” and set the value to NO in your info.plist.

By disabling the “View controller-based status bar appearance”, you can set the status bar style by using the following code.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; //objective-c

Hence it should solve "I can't change the color of my Status Bar when I'm using Over Full Screen option"



来源:https://stackoverflow.com/questions/43088920/swift-3-how-to-hide-status-bar-when-using-over-full-screen

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