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
}
Maybe not a solution to the OP problem, but what could also be the cause for
prefersStatusBarHidden
not being called is if you have used a second window in your app delegate, eg for displaying a splash screen, and you did not hide it after the splash was shown - then that window gets the events that lead to calling these functions.Firstly,
View controller-based status bar appearance
in the.plist
file must be set to YES.For Objective-C:
For Swift:
.m
file, just implement:For Objective-C:
For Swift:
If you have other
window
not hidden, the method not be called. Just hide other window, it will work as you wishWhen we nested the UINavigationController, our AppDelegate. Window. RootViewController Usually we create navigationController when first will call in the navigationController childViewControllerForStatusBarHidden function, because the default returns nil, then is called navigationController prefersStatusBarHidden function itself, So the status bar that we set in viewController through the prefersStatusBarHidden function will not be called, so it won't work. So we're going to create our own one that inherits from the NavigationController,in this subclass ChildViewControllerForStatusBarHidden function.
For swift 3, first, make sure that
View controller-based status bar appearance
is set toYES
in yourInfo
plist fileAnd then just add this to your view controller:
I hope this helps people in the future.
Figured it out. in info.plist file: view controller-status bar appearance should be set to YES