iOS 7 - Hide status bar on a child view controller

2019-05-07 14:22发布

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

2条回答
做个烂人
2楼-- · 2019-05-07 15:19

ViewControllerA should override childViewControllerForStatusBarHidden and return ViewControllerB.

- (UIViewController *)childViewControllerForStatusBarHidden {
    return _viewControllerB;
}
查看更多
smile是对你的礼貌
3楼-- · 2019-05-07 15:21

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.

查看更多
登录 后发表回答