我跟着这个主题来覆盖 -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 $ c $如果您使用此方法,请在plist文件中输入否。
Note that you'll also need to set UIViewControllerBasedStatusBarAppearance to NO in the plist file if you use this method.
更多推荐
不调用preferredStatusBarStyle
发布评论