隐藏状态栏swift 4 [英] hide status bar swift 4
本文介绍了隐藏状态栏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 addedsetNeedsStatusBarAppearanceUpdate()
function to force theprefersStatusBarHidden
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屋!
查看全文