The iOS code control status bar StatusBar preferredStatusBarStyle does not respond


IOS status bar settings, there is a lot of information on the network can refer to. The purpose of this article is to point out that when the StausBar is controlled by code, the trigger condition has been triggered if the preferredStatusBarStyle is not answered. The iOS SDK described in this article is written on the basis of iOS10.0. The minimum support iOS8.0

Meet problems:

About code control status bar. Many times I met in ViewController, rewritten

– – (UIStatusBarStyle) preferredStatusBarStyle

The ViewController then calls the status bar to update

[self setNeedsstatusBarAppearanceUpdate];

– (UIStatusBarStyle) preferredStatusBarStyle is not triggered.

Cause of the problem:

In fact, the reason lies in. No – – (UIStatusBarStyle) preferredStatusBarStyle is not triggered. Instead, this trigger will only be in the [UIApplication sharedApplication].window.rootViewController ViewController. Including [selfsetNeedsstatusBarAppearanceUpdate]; the call trigger is also in this [UIApplication sharedApplication].window.rootViewController. So?. This occurs because your current ViewController is not [UIApplication sharedApplication].window.rootViewController; as mentioned above, the code set in the status bar of the local [UIApplication sharedApplication].window.rootViewController.


Respond to

– (UIStatusBarStyle) preferredStatusBarStyle


[self setNeedsstatusBarAppearanceUpdate];

It’s in [UIApplication sharedApplication].window.rootViewController. It means change the activation method used in [UIApplication [selfsetNeedsstatusBarAppearanceUpdate]; sharedApplication].window.rootViewController, response (UIStatusBarStyle) preferredStatusBarStyle is in [UIApplication sharedApplication].window.rootViewControlle.