Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 - Hide status bar on a child view controller

UIApplication.SharedApplication.SetStatusBarHidden(MonoTouch code, but also applies to Obj-C) does the job for iOS 6, but for iOS 7 we must:

  1. Invoke SetNeedsStatusBarAppearanceUpdate () on the view controller (e.g.: a view controller that is showing a fullscreen image)
  2. Override PrefersStatusBarHidden () on the same view controller.

However the view controller mentioned above is embedded in a navigation controller, which is also embedded in a slideout menu. Even though all embedded view controllers are added to the hierarchy using AddChildViewController(), attempting to update the status bar in a child view controller has no effect.

Any ideas?


EDIT

Window.RootViewController (Menu)
|___ ViewControllerA (Navigation Bar)
     |___ ViewControllerB (Actual View controller)

Where ViewControllerB wants to hide/show the status bar

like image 527
Eduardo Coelho Avatar asked Feb 15 '23 05:02

Eduardo Coelho


2 Answers

ViewControllerA should override childViewControllerForStatusBarHidden and return ViewControllerB.

- (UIViewController *)childViewControllerForStatusBarHidden {
    return _viewControllerB;
}
like image 120
davidisdk Avatar answered Feb 28 '23 04:02

davidisdk


It does not appear entirely what you attempt to do. If you simple want to hide the statusbar in all child viewcontrollers, you could set the new plist propertyUIViewControllerBasedStatusBarAppearance.

... If you prefer to opt out of this behavior and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO.

source:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1

The source is BTW a really good reference to all kinds of information related to the handling of UINavigationBar and UIStatusBar in iOS7.

like image 44
EsbenB Avatar answered Feb 28 '23 04:02

EsbenB