Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prefersStatusBarHidden not called

Tags:

ios

statusbar

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
}
like image 566
Md1079 Avatar asked Nov 05 '15 09:11

Md1079


2 Answers

Firstly, View controller-based status bar appearance in the .plist file must be set to YES.

  • If you want status bar to be hidden in the whole app:

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
}
  • If you want status bar is disappeared in Specify View Controller, in .m file, just implement:

For Objective-C:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

For Swift:

override func prefersStatusBarHidden() -> Bool {
    return true
}
like image 71
Nghia Luong Avatar answered Nov 12 '22 11:11

Nghia Luong


Figured it out. in info.plist file: view controller-status bar appearance should be set to YES

like image 24
Md1079 Avatar answered Nov 12 '22 11:11

Md1079