不调用preferredStatusBarStyle

编程入门 行业动态 更新时间:2024-10-23 11:30:04
本文介绍了不调用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.

UIViewController ,其中我实现了 preferredStatusBarStyle 用于 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.

当我设置root时视图控制器指向此 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];

请注意,您还需要设置 UIViewControllerBasedStatusBarAppearance

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

更多推荐

不调用preferredStatusBarStyle

本文发布于:2023-10-28 19:20:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:preferredStatusBarStyle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!