UIViewController's prefersStatusBarHidden not working

前端 未结 4 594
星月不相逢
星月不相逢 2020-12-23 11:21

I am trying to make the status bar for one of my view controllers to be hidden (when displayed modally). When I\'m presenting the view controller, the status bar is is to be

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 12:00

    In iOS7, there's actually a new property for UIViewController called modalPresentationCapturesStatusBarAppearance. Apple iOS reference.

    Default value is NO.

    When you present a view controller by calling the presentViewController:animated:completion: method, status bar appearance control is transferred from the presenting to the presented view controller only if the presented controller’s modalPresentationStyle value is UIModalPresentationFullScreen. By setting this property to YES, you specify the presented view controller controls status bar appearance, even though presented non–fullscreen.

    The system ignores this property’s value for a view controller presented fullscreen.

    Therefore, for any presentationStyle other than the normal fullscreen (for example: UIModalPresentationCustom), this must be set if you want to capture the status bar. To use, all you have to do is set it to YES on the view controller that's being presented:

    toVC.modalPresentationCapturesStatusBarAppearance = YES;
    

提交回复
热议问题