隐藏状态栏swift 4 [英] hide status bar swift 4

查看:296
本文介绍了隐藏状态栏swift 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的一个UIViewControllers中隐藏状态栏(Swift 4).

I am trying to hide status bar in one of my UIViewControllers (Swift 4).

  • 首先,我在Info.plist中将基于视图控制器的状态栏外观设置为 YES .

我在控制器中覆盖了prefersStatusBarHidden属性:

I overrode the prefersStatusBarHidden property in my controller:

override var prefersStatusBarHidden: Bool {
     return true
}


  • viewDidLoad()中,我添加了setNeedsStatusBarAppearanceUpdate()函数以强制读取prefersStatusBarHidden属性.

    • And in viewDidLoad(), I added setNeedsStatusBarAppearanceUpdate() function to force the prefersStatusBarHidden property to be read.
    • 毕竟,我仍然在该UIViewController上看到状态栏.

      After all that, I still see the status bar on that UIViewController.

      有人可以帮我吗?

      推荐答案

      您可能已经找到了自己的解决方案,但是我以这种方式进行了工作:

      You probably found your own solution to this already, but I got it working this way:

      override func viewWillAppear(_ animated: Bool) {
          // Sets the status bar to hidden when the view has finished appearing
          let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
          statusBar.isHidden = true
      }
      
      override func viewWillDisappear(_ animated: Bool) {
          // Sets the status bar to visible when the view is about to disappear
          let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
          statusBar.isHidden = false
      }
      

      这篇关于隐藏状态栏swift 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆