How can I hide the status bar in iOS 7.1?

佐手、 提交于 2019-12-20 11:56:54

问题


In iOS 7.0, I hid the status bar in my apps by adding

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

to the info.plist. I just updated my testing iPad to iOS 7.1, and the status bar is now back in all of my apps. How can I hide it in both 7.0 and 7.1?

Update: This is only happening in iPhone apps running on the iPad, I don't see this problem on the iPhone or in the simulator.


回答1:


In the view controllers in which you want the status bar hidden, add the following method

- (BOOL)preferStatusBarHidden {
  return YES;
}

Then you can call

[self setNeedsStatusBarAppearanceUpdate];

which will fire the change to the status bar. This call can be done inside of an animation block which will animate the change.




回答2:


Try adding the following

   - (void)viewWillAppear:(BOOL)animated{
        NSLog(@"View will appear");
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

    }

    - (void)viewWillDisappear:(BOOL)animated{

        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    }



回答3:


I can reproduce the problem with a single-view iPhone-only app running in iPhone-compatibility mode in the simulator. But only when selecting an iPad non-retina on iOS 7.1.

My findings:

  • The status bar will not be hidden, whatever you specified in the plist or in code.
  • The problem doesn't occur on retina iPads
  • The problem doesn't occur on iOS 7 or iOS 6

I tried these keys in the .plist:

<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>

and

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIViewControllerBasedStatusBarAppearance~ipad</key>
<false/>

I also tried the ViewController based-solution as mentioned by @Irfan to no avail.

There also seems no way to detect if the statusbar is shown as [UIApplication sharedApplication].statusBarFrame returns {0, 0, 0, 0}




回答4:


Add this to ViewDidLoad:

 [[UIApplication sharedApplication] setStatusBarHidden:YES
                                        withAnimation:UIStatusBarAnimationFade];

And Implement below Method:

- (BOOL)prefersStatusBarHidden {
return YES;
 }

It will hide status-bar of that particular ViewController in which you Implement it. It works superbly good for me. Hopefully it will also help you out.




回答5:


The only solution I have found to this is to add the following:

- (UIStatusBarStyle) preferredStatusBarStyle {
    return -1;
}

wherever you have:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

This is obviously terrible, but it seems to work for me -- at least so far.

UPDATE: I have noticed this causing output like the following:

<Error>: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

I find another workaround, and it's possible that this error is what makes this workaround work, so I'm sticking with it, but it's worth noting.



来源:https://stackoverflow.com/questions/22309834/how-can-i-hide-the-status-bar-in-ios-7-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!