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
}
Firstly, View controller-based status bar appearance
in the .plist
file must be set to YES.
For Objective-C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];
return YES;
}
For Swift:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
application.statusBarHidden = true
return true
}
.m
file, just implement:For Objective-C:
- (BOOL)prefersStatusBarHidden {
return YES;
}
For Swift:
override func prefersStatusBarHidden() -> Bool {
return true
}