IOS7 Status bar hide/show on select controllers

后端 未结 5 1440
北荒
北荒 2020-12-01 01:46

I would like to show and hide the Status bar on some controllers. Can this be done or is it more of an overall app setting.

I have seen many posts/questions about th

5条回答
  •  醉话见心
    2020-12-01 02:30

    The plist setting "View controller-based status bar appearance" only controls if a per-controller based setting should be applied on iOS 7.

    If you set this plist option to NO, you have to manually enable and disable the status bar like (as it was until iOS 6):

    [[UIApplication sharedApplication] setStatusBarHidden:YES]
    

    If you set this plist option to YES, you can add this method to each of your viewControllers to set the statusBar independently for each controller (which is esp. nice if you have a smart subclass system of viewControllers)

    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    

    Edit:

    there are two more methods that are of interest if you are opting in the new viewController-based status bar appearance -

    Force a statusbar update with:

    [self setNeedsStatusBarAppearanceUpdate]
    

    If you have nested controllers (e.g. a contentViewController in a TabBarController subclass, your TabBarController subclass might ask it's current childViewController and forward this setting. I think in your specific case that might be of use:

    - (UIViewController *)childViewControllerForStatusBarHidden {
         return _myChildViewController;
    }
    - (UIViewController *)childViewControllerForStatusBarStyle {
         return _myOtherViewController;
    }
    

提交回复
热议问题