未调用 preferredStatusBarStyle [英] preferredStatusBarStyle isn't called

查看:39
本文介绍了未调用 preferredStatusBarStyle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了这个帖子覆盖 -preferredStatusBarStyle,但它没有被调用.是否有任何选项可以更改以启用它?(我在我的项目中使用了 XIB.)

I followed this thread to override -preferredStatusBarStyle, but it isn't called. Are there any options that I can change to enable it? (I'm using XIBs in my project.)

推荐答案

可能的根本原因

我遇到了同样的问题,并发现它正在发生,因为我没有在我的应用程序窗口中设置根视图控制器.

Possible root cause

I had the same problem, and figured out it was happening because I wasn't setting the root view controller in my application window.

我在其中实现了 preferredStatusBarStyleUIViewController 被用在 UITabBarController 中,它控制了屏幕上视图的外观.

The UIViewController in which I had implemented the preferredStatusBarStyle was used in a UITabBarController, which controlled the appearance of the views on the screen.

当我将根视图控制器设置为指向此 UITabBarController 时,状态栏更改开始正常工作,如预期(并且 preferredStatusBarStyle 方法被调用).

When I set the root view controller to point to this UITabBarController, the status bar changes started to work correctly, as expected (and the preferredStatusBarStyle method was getting called).

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ... // other view controller loading/setup code

    self.window.rootViewController = rootTabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

替代方法(iOS 9 中已弃用)

或者,您可以根据背景颜色在每个视图控制器中酌情调用以下方法之一,而不必使用 setNeedsStatusBarAppearanceUpdate:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

请注意,如果您使用此方法,您还需要在 plist 文件中将 UIViewControllerBasedStatusBarAppearance 设置为 NO.

Note that you'll also need to set UIViewControllerBasedStatusBarAppearance to NO in the plist file if you use this method.

这篇关于未调用 preferredStatusBarStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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