Swift 3 | Unable to hide status bar on a ViewController

旧城冷巷雨未停 提交于 2020-03-06 00:59:29

问题


I want to show the status bar on portrait mode only, when I rotate the screen the status bar hides as intended but if I push / show a new View Controller the status bar appears again.

I've tried the following without success:

  • Setting View controller-based status bar appearance to NO in the info.plist file
  • Using setNeedsStatusBarAppearanceUpdate() on self and on NavigationController
  • Setting prefersStatusBarHidden: Bool to true
  • Also tried UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.none)
  • Also extending NavigationController. seen here

Any help will be appreciated. Thanks.


回答1:


Try Following Code

override var prefersStatusBarHidden: Bool {

    if UIDevice.current.orientation.isPortrait{
        return false
    }
    return true
}


来源:https://stackoverflow.com/questions/42788577/swift-3-unable-to-hide-status-bar-on-a-viewcontroller

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