In the Info.plist file, the view controller-based status bar appearance is set to Yes, and the view controller has a higher priority on the status bar than the application setting. If no is set to application, the Prefersstatusbarhidden method of view controller is invalid and is not called at all.
First, if view controller-based status bar appearance is set to Yes.
When the view Controller has a priority setting of status bar higher than the application setting, the status bar is hidden in the following way:
1. Call Setneedsstatusbarappearanceupdate in the View controller to update the display of the status bar.
-(void) Viewdidappear: (BOOL) animated
{
[Super viewdidappear:animated];
if ([Self respondstoselector: @selector (setneedsstatusbarappearanceupdate)]) {
[Self Prefersstatusbarhidden];
[Self performselector: @selector (setneedsstatusbarappearanceupdate)];
}
}
2. The implementation of the Prefersstatusbarhidden of the view controller will be returned to Yes.
-(BOOL) Prefersstatusbarhidden
{
return YES;
}
Second, if the View controller-based status bar appearance is set to No, then the application setting has the highest priority, hiding the status bar in the following way:
[[UIApplication sharedapplication] Setstatusbarhidden:yes Withanimation:no];
Combined with the above conclusions, if both IOS6 and iOS7 are supported, the process is as follows:
First, if view controller-based status bar appearance is set to No.
Both iOS6 and iOS7 hide the status bar in the following way.
[[UIApplication sharedapplication] Setstatusbarhidden:yes Withanimation:no];
Second, if view controller-based status bar appearance is set to Yes.
You need to determine whether the current is iOS6 or iOS7. If it is iOS6, it is also hidden through sharedapplication.
If it is iOS7, hide the status bar in a setneedsstatusbarappearanceupdate plus prefersstatusbarhidden way.
Take the settings in the View controller-based status bar appearance in Info.plist:
NSNumber *isvcbasedstatusbarappearancenum = [[NSBundle mainbundle]objectforinfodictionarykey:@] Uiviewcontrollerbasedstatusbarappearance "];
if (isvcbasedstatusbarappearancenum) {
_isvcbasedstatusbarappearance = Isvcbasedstatusbarappearancenum.boolvalue;
} else {
_isvcbasedstatusbarappearance = YES; Default
}
iOS Development UI Chapter-view controller-based status bar appearance