iOS 7 - Hide status bar on a child view controller

与世无争的帅哥 提交于 2019-12-10 09:25:26

问题


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


回答1:


ViewControllerA should override childViewControllerForStatusBarHidden and return ViewControllerB.

- (UIViewController *)childViewControllerForStatusBarHidden {
    return _viewControllerB;
}



回答2:


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.



来源:https://stackoverflow.com/questions/18934565/ios-7-hide-status-bar-on-a-child-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!