IOS7, not only the application style has certain changes, the status bar changes relatively large, we can see The Uiviewcontroller status bar is basically one with the navigation bar. So the method of hide/show state of Uiviewcontroller is not the same as other versions. In previous versions of IOS7, Hide/show was implemented with the following code
[CPP]View Plain copy
- [[UIApplication Sharedapplication] Setstatusbarhidden:yes (NO) withanimation:uistatusbaranimationslide];
This method is not successful by default in IOS7. To setstatusbarhidden:withanimation: Declaration of the header file to see, more than a note://Setting Statusbarhidden does nothing if your application is using The default uiviewcontroller-based status bar system. Now in IOS7, the appearance of the status bar depends on Uiviewcontroller, which means that the status bar varies with uiviewcontroller. In this default way, the global approach to setstatusbarhidden:withanimation: is not feasible.
Google found that there are two ways to solve the problem now:
If you are simply hiding the status bar, then by default, you only need to re-implement two new methods
[CPP]View Plain copy
- - (Uistatusbarstyle) preferredstatusbarstyle
- {
- return uistatusbarstylelightcontent;
- // uistatusbarstyledefault = 0 black text, with light background;
- < span class= "comment" >//uistatusbarstylelightcontent = 1 white text with a dark background using
- }
- &NBSP;&NBSP;
- - (bool) prefersstatusbarhidden
- {&NBSP;&NBSP;
- < span class= "keyword" >return no; //return NO means to show, return Yes hiden
- }&NBSP;&NBSP;
The previous callback method returns the style when the status bar is displayed, and the following callback controls whether the status bar is displayed.
Calling the following line of code will trigger the callback above
[CPP]View Plain copy
- [Self setneedsstatusbarappearanceupdate];
If you want to have a little animation between hiden/show, use the following code:
[CPP]View Plain copy
- [UIView animatewithduration:0.5 animations:^{
- [Self setneedsstatusbarappearanceupdate];
- }];
or call the following code:
[CPP]View Plain copy
- [[UIApplication sharedapplication] Setstatusbarhidden:yes withanimation:uistatusbaranimationslide];
in setting this up, we'll still find that the status bar is not there, but instead it's a black area, so we'll also need to adjust the Uiviewcontroller view with the following code:
[CPP]View Plain copy
- -(void) Viewdidlayoutsubviews
- {
- CGRect viewbounds = self.view.bounds;
- CGFloat topbaroffset = 20.0;
- VIEWBOUNDS.ORIGIN.Y =-topbaroffset;
- Self.view.bounds = Viewbounds;
- [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent]; //for status bar style
- }
Hidden status bar of iOS