I have a UITabViewController
-> UINavigationController
-> UIViewController
and want to hide and unhide the statusBar. when I call setNeedsStatusBarAppearanceUpdate()
the method prefersStatusBarHidden
is not called.
func fadeOutStatusBar (notification: NSNotification) {
statusBarHidden = true
self.setNeedsStatusBarAppearanceUpdate()
}
func fadeInStatusBar (notification: NSNotification) {
statusBarHidden = false
self.setNeedsStatusBarAppearanceUpdate()
}
override func prefersStatusBarHidden() -> Bool {
return statusBarHidden
}
you can write an extension of UINavigationController that overrides its default implementation and returns the top ViewController.
Property
prefersStatusBarHidden
is being called on the root view controller of the current view controller.This means that if your app is based on a
UISplitViewController
for example, you must implement the property in a customUISplitViewController
class.For Swift 4.2 iOS 12
Assuming you have a
ViewController
contained withinUINavigationController
. Create your own Subclass ofUINavigationController
and include in it:Make sure
info.plist
setsView Controller
based setting of status bar