UIApplication.statusBarStyle在viewWillAppear和viewDidAppear之间切换 [英] UIApplication.statusBarStyle changes between viewWillAppear and viewDidAppear

查看:121
本文介绍了UIApplication.statusBarStyle在viewWillAppear和viewDidAppear之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最初为以前版本设计的iOS7中运行应用程序时,深灰色导航栏会将状态栏显示为黑色。

Running an app in iOS7 initially designed for previous versions, a dark grey navigation bar tints the status bar whose text is black.

我正在尝试调整它到最新版本,我将UIApplication.statusBarStyle设置为UIStatusBarStyleLightContent,如下所示:

I'm trying to adapt it to the newest version, and I'm setting the UIApplication.statusBarStyle to UIStatusBarStyleLightContent like this:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

这段代码应该将状态栏文本颜色更改为白色,但事实并非如此。我在我的UIApplication实例的_statusBarRequestedStyle属性中放置了一个观察点,我可以通过执行viewWillAppear和viewDidAppear方法之间的UIApplicationMain调用将其设置为0(UIStatusBarStyleDefault)。

This piece of code should change the status bar text colour to white but it doesn't. I put a watchpoint in the _statusBarRequestedStyle property of my UIApplication instance and I could see that this is set to 0 (UIStatusBarStyleDefault) by some call from UIApplicationMain between the execution of viewWillAppear and viewDidAppear methods.

我无法弄清楚状态栏样式在这一点上有什么/为什么会改变,如果您有相同的经验,我将不胜感激。

I can't figure out what/why the status bar style is changed at this point and I would appreciate any advice if you have experienced the same.

提前致谢!

编辑:
来自iOS 7 UI过渡指南( https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/Bars.html


在iOS 7中,您可以从单个视图控制器控制状态栏的样式,并在应用程序运行时进行更改。如果您希望选择不使用此行为并使用UIApplication statusBarStyle方法设置状态栏样式,请将UIViewControllerBasedStatusBarAppearance键添加到应用程序的Info.plist文件中,并为其指定值NO。

In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. 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.


推荐答案

我认为系统正在根据视图控制器状态栏外观更新状态栏。这是iOS7的新行为,默认情况下处于启用状态。

I think what happens is the system is updating the status bar according to the view controller status bar appearance. This is new behavior to iOS7, and is on by default.

如果要将以前的API用于状态栏外观,则应设置你应用的info.plist中的UIViewControllerBasedStatusBarAppearance NO

If you want to use the previous API for status bar appearance, you should set UIViewControllerBasedStatusBarAppearance to NO in your app's info.plist.

这篇关于UIApplication.statusBarStyle在viewWillAppear和viewDidAppear之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆