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 }
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?
Navigate to Android > Restrictions > Advanced and click on Configure. Under Display Settings, you'll have the following options. Hide System Bars – You can hide/display the system bars using this option.
Use statusBar(hidden:) to show or hide the status bar.
To completely hide it on the home screen, open up an app, such as Settings, and wait about three to four seconds. Press the home button again, and the status bar will be completely gone.
You can hide the status bar in any or all of your view controllers just by adding this code:
override var prefersStatusBarHidden: Bool { return true }
Any view controller containing that code will hide the status bar by default.
If you want to animate the status bar in or out, just call setNeedsStatusBarAppearanceUpdate() on your view controller – that will force prefersStatusBarHidden to be read again, at which point you can return a different value. If you want, your call to setNeedsStatusBarAppearanceUpdate() can actually be inside an animation block, which causes the status bar to hide or show in a smooth way.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With