How to hide status bar in iOS 7?

末鹿安然 提交于 2019-12-08 01:34:22

问题


I have tried setting the following in my app .plist file:

View controller-based status bar appearance: NO

And while this removes it from my initial view controller, once I go to another view and come back with my navigation controller, it comes right back and this time it does not disappear. Also, I don't see why it would matter but I have also set the status bar under simulated metrics to "None" but that doesn't seem to help. I know i am going to have the navigation bar but the status bar I need gone.

How can I get this done? Please provide a detailed answer, sample code would be great!

Update: This is NOT a duplicate solution as I have tried all other solutions and NONE seem to work for me. Most recently I tried

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

Again, with no results. When the app initially launches a status bar is NOT present, after the user visits another view, the status bar is now present in the 2 and other views and does not go away. Even if you go back to the main view.


回答1:


I have tried all of the suggestions that were posted here, unfortunately what happened here was a small mistake, in my viewDidLoad I had:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

But in my viewWillAppear I had:

[[UIApplication sharedApplication] setStatusBarHidden:NO];

So this was just an issue of overriding, problem fixed now.




回答2:


To hide status bar:

if [View controller-based status bar appearance: NO]: in AppDelegate.m call

[[UIApplication sharedApplication]setStatusBarHidden:YES];

else: in every view controller

- (BOOL)prefersStatusBarHidden
{
    return YES;
}



回答3:


Try this 2 steps:

  1. In .Plist file of project set the property:

View controller-based status bar appearance = NO;

and 2.In all view controller's .m file in viewDidLoad method put this line of code:

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



回答4:


Use this method in the View Controller which you'd like the Status Bar hidden:

- (BOOL)prefersStatusBarHidden {
    return YES;
}



回答5:


This should work :

// In iOS7 this gets called and hides the status bar so the view does not go under the top iPhone
// status bar

- (BOOL)prefersStatusBarHidden {
      return YES;
}



回答6:


none of these work for me. when i try this method i get the message "use of undeclared identifier preferstatusbarHidden

include - (BOOL)prefersStatusBarHidden {
      return YES;
}



回答7:


I don't know what to do anymore. I tried setStatusBarHidden, prefersHiddenStatusBar and still no results. Finally i have went through the below you tube link :

https://www.youtube.com/watch?v=FtpBXdMSqRQ

It worked for me.



来源:https://stackoverflow.com/questions/19826320/how-to-hide-status-bar-in-ios-7

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