ios 9 statusBar style

来源:互联网 发布:java web 线程池 编辑:程序博客网 时间:2024/06/05 10:07
-(UIStatusBarStyle)preferredStatusBarStyle;-(BOOL)prefersStatusBarHidden;

1、子类重写viewController以上两个方法,能够正常调用.
2、在navigtioncontroller 容器中的viewcontroller的上述方法不能够正常调用,系统根据navigtionController navigtaionbarstyle 确定statusbar 状态。

以下内容来自链接:
http://stackoverflow.com/questions/19022210/preferredstatusbarstyle-isnt-called/19513714#19513714

The UINavigationController does not forward on preferredStatusBarStyle
calls to its child view controllers. Instead it manages its own state
- as it should, it is drawing at the top of the screen where the status bar lives and so should be responsible for it. Therefor
implementing preferredStatusBarStyle in your VCs within a nav
controller will do nothing - they will never be called.

The trick is what the UINavigationController uses to decide what to
return for UIStatusBarStyleDefault or UIStatusBarStyleLightContent. It
bases this on it’s UINavigationBar.barStyle. The default
(UIBarStyleDefault) results in the dark foreground
UIStatusBarStyleDefault status bar. And UIBarStyleBlack will give a
UIStatusBarStyleLightContent status bar.

If you want UIStatusBarStyleLightContent on a UINavigationController
use: self.navigationController.navigationBar.barStyle =
UIBarStyleBlack;

3、需要navigation容器中viewcontroller以上方法调用,可以写两个navigtioncontroller 的类别,放入工程中,就会自己调用,(前提:plist文件中 View controller-based status bar appearance 需要设置为 YES)代码如下:

-(UIViewController *)childViewControllerForStatusBarStyle {    return self.topViewController;}-(UIViewController *)childViewControllerForStatusBarHidden {    return self.topViewController;}
0 0
原创粉丝点击