atusBarStyle在viewWillAppear和view

atusBarStyle在viewWillAppear和view

本文介绍了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过渡指南()


推荐答案

我认为系统正在根据视图控制器状态栏外观更新状态栏。这是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之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:08