I am trying to hide status bar in one of my UIViewControllers (Swift 4).
Firstly, I set View controller-based status bar appearance to YES in Info.plist.
I overrode the prefersStatusBarHidden property in my controller:
override var prefersStatusBarHidden: Bool {
return true
}
And in viewDidLoad(), I added setNeedsStatusBarAppearanceUpdate() function to force the prefersStatusBarHidden property to be read.
After all that, I still see the status bar on that UIViewController.
Can someone help me, please?
解決方案
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
}