objective-c 无法在 iOS7 中隐藏状态栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18059703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:55:09  来源:igfitidea点击:

Cannot hide status bar in iOS7

objective-cstatusbarios7

提问by Melih Büyükbayram

I just upgraded my iPhone 5 iOS 7 to four beta version. Now when I run my app from Xcode 5 on this iPhone, status bar doesn't hide, even though it should.

我刚刚将我的 iPhone 5 iOS 7 升级到了四个测试版。现在,当我在这台 iPhone 上从 Xcode 5 运行我的应用程序时,状态栏不会隐藏,即使它应该隐藏。

Not Working:

不工作:

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

Not Working:

不工作:

[UIApplication sharedApplication].statusBarHidden = YES;

Can't login to Apple Developer Forums

无法登录 Apple 开发者论坛

回答by satgi

in your apps plist file add a row call it "View controller-based status bar appearance" and set it to NO

在您的应用程序 plist 文件中添加一行,称为“查看基于控制器的状态栏外观”并将其设置为 NO

Note that this simply does not work, if you are using UIImagePickerController in the app.

请注意,如果您在应用程序中使用 UIImagePickerController,这根本不起作用。

from http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/, mgiroux's solution

来自http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/,mgiroux 的解决方案

An example adding View Base Controller to your Info settings in Xcode

将 View Base Controller 添加到 Xcode 中的信息设置的示例

回答by invoodoo

Add method in your view controller.

在视图控制器中添加方法。

- (BOOL)prefersStatusBarHidden {
    return YES;
}

回答by user1179912

In the Plist add the following properties.

在 Plist 中添加以下属性。

-> Status bar is initially hidden= YES

-> Status bar is initially hidden= 是

-> View controller-based status bar appearance= NO

-> View controller-based status bar appearance= 否

Add both - now the status bar will disappear.

添加两者 - 现在状态栏将消失。

回答by Debora Fortini

To hide Status Bar on a Single view, you should use:

要在单个视图上隐藏状态栏,您应该使用:

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

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

At first, this didn't work for me, and then a saw in the documentation of this method that says: // Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.

起初,这对我不起作用,然后在此方法的文档中看到: // 如果您的应用程序使用基于 UIViewController 的默认状态栏系统,则设置 statusBarHidden 什么也不做。

This has to be done on the plist file, adding the key View controller-based status bar appearanceset to NO. And then it worked.

这必须在 plist 文件上完成,将密钥View controller-based status bar appearance集添加到NO. 然后它起作用了。

回答by Shaik Riyaz

To hide status bar in iOS7 you need 2 lines of code

要在 iOS7 中隐藏状态栏,您需要 2 行代码

  1. inapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionswrite

    [application setStatusBarHidden:YES];
    
  2. in info.plist add this

    View-Controller Based Status Bar Appearance = NO
    
  1. 应用:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    [application setStatusBarHidden:YES];
    
  2. 在 info.plist 添加这个

    View-Controller Based Status Bar Appearance = NO
    

回答by jaredsinclair

In order to use the legacy UIApplication method to hide/show the status bar, your app must set a plist value for iOS 7:

为了使用旧的 UIApplication 方法来隐藏/显示状态栏,您的应用程序必须为 iOS 7 设置一个 plist 值:

View-Controller Based Status Bar Appearance = NO

View-Controller Based Status Bar Appearance = NO

This value is set to YES by default. If you change it to NO, you can use the legacy methods. If you leave it set to YES, you can still hide the status bar, but it's up to each view controller subclass in your app to override: prefersStatusBarHiddento return YES.

默认情况下,此值设置为 YES。如果将其更改为 NO,则可以使用旧方法。如果您将其设置为 YES,您仍然可以隐藏状态栏,但由您的应用程序中的每个视图控制器子类来覆盖:prefersStatusBarHidden返回 YES。

Any time your app needs the status bar appearance or visibility to change, and View-Controller Based Status Bar Appearance is set to YES, your outermost view controller needs to call:

任何时候您的应用程序需要更改状态栏外观或可见性,并且基于视图控制器的状态栏外观设置为 YES,您最外层的视图控制器需要调用:

setNeedsStatusBarAppearanceUpdateAnimation

setNeedsStatusBarAppearanceUpdateAnimation

回答by SaltyNuts

There are so many combinations suggested for this issue, but the problem is that iOS 6 and 7 use different methods to hide the status bar. I have never been successful setting the plist settings to enable the iOS6-style behaviour on iOS 7, but if you are building your app to support iOS 6+, you need to use 3 methods at once to ensure a particular view controller hides the status bar:

针对这个问题建议的组合太多了,但问题是iOS 6和7使用不同的方法来隐藏状态栏。我从来没有成功设置 plist 设置以在 iOS 7 上启用 iOS6 风格的行为,但是如果您正在构建您的应用程序以支持 iOS 6+,您需要一次使用 3 种方法来确保特定的视图控制器隐藏状态酒吧:

// for ios 7 
- (BOOL)prefersStatusBarHidden{
    return YES;
}

// for ios 6
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // explicitly set the bar to show or it will remain hidden for other view controllers
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

This should work regardless of your plist settings.

无论您的 plist 设置如何,这都应该有效。

回答by Peter Y

I had to do both changes below to hide the status bar:

我必须进行以下两项更改才能隐藏状态栏:

Add this code to the view controller where you want to hide the status bar:

将此代码添加到要隐藏状态栏的视图控制器:

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

Add this to your .plist file (go to 'info' in your application settings)

将此添加到您的 .plist 文件(转到应用程序设置中的“信息”)

View controller-based status bar appearance --- NO

Then you can call this line to hide the status bar:

然后你可以调用这一行来隐藏状态栏:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

回答by Sid

Just add these 2 lines in info.plist file. It will make the fix for iOS7 and older version both.

只需在 info.plist 文件中添加这两行。它将修复 iOS7 和旧版本。

  • Status bar is initially hidden = YES
  • View controller-based status bar appearance = NO
  • 状态栏最初是隐藏的 = YES
  • 基于视图控制器的状态栏外观 = NO

Navigate to the project and select Targets -> General and see the "Status Bar style ...Hide during application launch" check box will be checked. This will work.

导航到项目并选择 Targets -> General 并查看“Status Bar style ...Hide during application launch”复选框将被选中。这将起作用。

回答by Rajesh Loganathan

Try this simple method:

试试这个简单的方法:

- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}