Transferred from: http://blog.csdn.net/dqjyong/article/details/17896145
IOS7, not only the application of the style has a certain change, the status bar changes relatively large, we can see the Uiviewcontroller status bar and navigation bar is basically a whole. 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 Plaincopy
- [[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 Plaincopy < param name= "wmode" value= "Transparent" >
- -(Uistatusbarstyle) Preferredstatusbarstyle
- {
- return uistatusbarstylelightcontent;
- //uistatusbarstyledefault = 0 Black text, used when light background
- //uistatusbarstylelightcontent = 1 white text, used when dark background
- }
- -(BOOL) Prefersstatusbarhidden
- {
- return NO; //Return no indicates to be displayed, return yes will hiden
- }
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 Plaincopy
- [Self setneedsstatusbarappearanceupdate];
If you want to have a little animation between hiden/show, use the following code:
[CPP]View Plaincopy
- [UIView animatewithduration:0.5 animations:^{
- [Self setneedsstatusbarappearanceupdate];
- }];
or call the following code:
[CPP]View Plaincopy
- [[UIApplication sharedapplication] Setstatusbarhidden:yes withanimation:uistatusbaranimationslide];
Another way is to add key:uiviewcontrollerbasedstatusbarappearance to the Infor.plist and set its value to No, which tells the system that the status Bar does not depend on Uiviewcontroller. This allows you to hiden the status bar using the above method.
In setting these, we will still find some problems, that is, although the status bar is not, but instead of a black area, so we also need to adjust the Uiviewcontroller view, the code is:
[CPP]View Plaincopy < param name= "wmode" value= "Transparent" >
- -(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
- }
IOS7 Hide Status bar State Bar