Hidden status bar of iOS

Source: Internet
Author: User

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
    1. [[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
    1. -  (Uistatusbarstyle) preferredstatusbarstyle  
    2. {  
    3.     return  uistatusbarstylelightcontent;  
    4.     // uistatusbarstyledefault = 0  black text,    with light background;
    5.   < span class= "comment" >//uistatusbarstylelightcontent = 1  white text with a dark background using   
    6. }  
    7. &NBSP;&NBSP;
    8. -  (bool) prefersstatusbarhidden  
    9. {&NBSP;&NBSP;
    10.     < span class= "keyword" >return no; //return NO means to show, return Yes hiden  
    11. }&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
    1. [Self setneedsstatusbarappearanceupdate];


If you want to have a little animation between hiden/show, use the following code:

[CPP]View Plain copy
    1. [UIView animatewithduration:0.5 animations:^{
    2. [Self setneedsstatusbarappearanceupdate];
    3. }];

or call the following code:

[CPP]View Plain copy
    1. [[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
      1. -(void) Viewdidlayoutsubviews
      2. {
      3. CGRect viewbounds = self.view.bounds;
      4. CGFloat topbaroffset = 20.0;
      5. VIEWBOUNDS.ORIGIN.Y =-topbaroffset;
      6. Self.view.bounds = Viewbounds;
      7. [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent]; //for status bar style
      8. }

Hidden status bar of iOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.