xcode iOS 故事板 - 禁用故事板上的状态栏一次

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8975869/
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-14 23:04:30  来源:igfitidea点击:

iOS storyboard - Disable status bar on storyboard once

iosxcodeuiviewcontrollerxcode-storyboard

提问by Romes

Is there a way in Xcodewhen using the Storyboardin the Interface Builderto disable the status bar completely, so that when I create a new View ControllerI don't keep having to turn "status bar" from inferred to none.

有没有办法在Xcode使用StoryboardinInterface Builder完全禁用状态栏时,这样当我创建一个新的时,View Controller我不必一直将“状态栏”从推断变为无。

采纳答案by Joris Kluivers

Have you already checked if setting UIStatusBarHiddento YESin your Info.plist works? See the documentation: http://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW15

你是否已经设置,如果检查UIStatusBarHiddenYES你的Info.plist的作品?请参阅文档:http: //developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW15

This will hide the status bar on application start.

这将隐藏应用程序启动时的状态栏。

回答by Ronny Webers

Here's a full iOS 7 compliant solution (not iOS 6 compatible though, as too many things have changed)

这是一个完整的 iOS 7 兼容解决方案(虽然不兼容 iOS 6,因为太多东西已经改变了)

from the Apple doc ‘ : Information Property List Key Reference' :

来自 Apple 文档“:信息属性列表关键参考”:

UIViewControllerBasedStatusBarAppearance(Boolean - iOS) specifies whether the status bar appearance is based on the style preferred by the view controller that is currently under the status bar. When this key is not present or its value is set to YES, the view controller determines the status bar style. When the key is set to NO, view controllers (or the app) must each set the status bar style explicitly using the UIApplication object. This key is supported in iOS 7.0 and later.

UIViewControllerBasedStatusBarAppearance(Boolean - iOS) 指定状态栏外观是否基于当前位于状态栏下方的视图控制器首选的样式。当此键不存在或其值设置为 YES 时,视图控制器确定状态栏样式。当键设置为 NO 时,视图控制器(或应用程序)必须使用 UIApplication 对象显式设置状态栏样式。iOS 7.0 及更高版本支持此密钥。

So by default this key is not present (= same behaviour as if you add the key, but set it to YES) : in this case each view controller determines the status bar behaviour, by overriding some methods - see below.

因此,默认情况下此键不存在(= 与添加键的行为相同,但将其设置为 YES):在这种情况下,每个视图控制器通过覆盖某些方法来确定状态栏行为 - 见下文。

1) Globaly show/hide the status bar all of your app's viewControllers

1) Globaly 显示/隐藏应用程序的所有视图控制器的状态栏

so first the full answer to your question, to make a single, global show/hide setting for all of your apps viewControllers

所以首先要完整回答你的问题,为你的所有应用程序 viewControllers 做一个单一的、全局的显示/隐藏设置

step 1 : in your frameWork-Info.plst' file, add the key ‘View controller-based status bar appearance' and set it to ‘NO'. Setting this key to 'NO' will make iOS 7 not call the methods 'prefersStatusBarHidden' and 'preferredStatusBarUpdateAnimation', see further on.

第 1 步:在您的 frameWork-Info.plst' 文件中,添加键“基于控制器的状态栏外观”并将其设置为“否”。将此键设置为“NO”将使 iOS 7 不调用方法“prefersStatusBarHidden”和“preferredStatusBarUpdateAnimation”,请参阅更多内容。

step 2 : in project settings -> general -> deployment info, select 'show/hide' during application launch

第 2 步:在项目设置 -> 常规 -> 部署信息中,在应用程序启动期间选择“显示/隐藏”

that's it : now you can globally show or hide the status bar, compliant with iOS 7

就是这样:现在您可以全局显示或隐藏状态栏,符合 iOS 7

2) Let all of your viewControllers have individual control over the status bar (= iOS 7 default)

2) 让你所有的 viewController 都可以单独控制状态栏(= iOS 7 默认)

step 1 : don't add the key, or add it, but set it to YES, to get the iOS 7 default behaviour

第 1 步:不要添加密钥,也不要添加它,而是将其设置为 YES,以获得 iOS 7 默认行为

step 2 : in each viewController you can now determine if you show/hide the statusbar by overriding :

第 2 步:在每个 viewController 中,您现在可以通过覆盖来确定是否显示/隐藏状态栏:

  • (BOOL)prefersStatusBarHidden
  • (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
  • (BOOL)prefersStatusBarHidden
  • (UIStatusBarAnimation)preferredStatusBarUpdateAnimation

so you need to override these 2 methods to control the statusbar behaviour, and return the appropriate value for your application (see doc ref for all possible values, it's clearly explained).

所以你需要覆盖这 2 种方法来控制状态栏行为,并为你的应用程序返回适当的值(所有可能的值参见文档参考,它有明确的解释)。

to control the behaviour during app launch (very first controller that is shown), set show/hide under your project settings -> general -> deployment info

要控制应用程序启动期间的行为(显示的第一个控制器),请在项目设置-> 常规-> 部署信息下设置显示/隐藏

Note that iOS 7 only supports a single appearance style (UIStatusBarStyleLightContent), all others are deprecated !

请注意,iOS 7 仅支持单一外观样式(UIStatusBarStyleLightContent),其他所有样式均已弃用!

You can thus easily toggle the bar on/off with a button for example - as flexible as possible !

例如,您可以使用按钮轻松地打开/关闭栏 - 尽可能灵活!

for example, add a button to your viewController, and a bool @property 'isStatusBarHidden' Use the following code to toggle the bar on/off with animation.

例如,向您的 viewController 添加一个按钮和一个 bool @property 'isStatusBarHidden' 使用以下代码通过动画切换栏的开/关。

- (BOOL)prefersStatusBarHidden
{
    return self.isStatusBarHidden;
}

- (IBAction)buttonToggleStatusBar:(UIButton *)sender
{
    [UIView animateWithDuration:1.0 animations:^{
        self.isStatusBarHidden = !self.isStatusBarHidden;
        [self setNeedsStatusBarAppearanceUpdate];
    }];

}

you can do the same for the preferred animation

您可以对首选动画执行相同操作

advanced note : if you want to set a default value for the @property 'isStatusBarHidden', you need to do so in 'initWithCoder' (called when using Storyboards), instead of viewDidLoad. The reason is that 'prefersStatusBarHidden' and 'preferredStatusBarUpdateAnimation' are called before 'viewDidLoad'

高级说明:如果要为@property 'isStatusBarHidden' 设置默认值,则需要在 'initWithCoder'(使用 Storyboard 时调用)而不是 viewDidLoad 中进行设置。原因是在 'viewDidLoad' 之前调用了 'prefersStatusBarHidden' 和 'preferredStatusBarUpdateAnimation'