iOS Storyboard - 禁用 Storyboard 上的状态栏一次
在 Interface Builder
中使用 Storyboard
时,Xcode
有没有办法完全禁用状态栏,这样当我创建新的 < code>View Controller 我不必一直将“状态栏”从推断为无。
Is there a way in Xcode
when using the Storyboard
in the Interface Builder
to disable the status bar completely, so that when I create a new View Controller
I don't keep having to turn "status bar" from inferred to none.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完整 iOS 7 兼容解决方案(但不兼容 iOS 6,因为太多内容已更改)
这是来自 Apple 文档“:信息属性列表键参考”的
: UIViewControllerBasedStatusBarAppearance(布尔值 - iOS)指定状态栏外观是否基于当前位于状态栏下方的视图控制器首选的样式。当此键不存在或其值设置为 YES 时,视图控制器确定状态栏样式。当该键设置为 NO 时,视图控制器(或应用程序)必须使用 UIApplication 对象显式设置状态栏样式。
iOS 7.0 及更高版本支持此键。
因此,默认情况下此键不存在(= 与添加该键的行为相同,但将其设置为 YES):在这种情况下,每个视图控制器确定状态栏行为,通过覆盖一些方法 - 见下文。
1) 全局显示/隐藏应用程序的所有视图控制器的状态栏,
因此首先要完整回答您的问题,为所有应用程序的视图控制器进行单个全局显示/隐藏设置
第 1 步:在“frameWork-Info.plst”文件中,添加“查看基于控制器的状态栏外观”键并将其设置为“否”。将此键设置为“NO”将使 iOS 7 不调用方法“prefersStatusBarHidden”和“preferredStatusBarUpdateAnimation”,请参阅进一步内容。
步骤2:在项目设置->一般->部署信息,在应用程序启动期间选择“显示/隐藏”
就是这样:现在您可以全局显示或隐藏状态栏,符合 iOS 7
2) 让您的所有 viewController 都可以单独控制状态栏 (= iOS 7 默认)
步骤 1:不添加该键,或者添加它,但将其设置为 YES,以获取 iOS 7 默认行为
步骤 2:在每个 viewController 中,您现在可以确定是否显示/隐藏通过覆盖:
因此您需要覆盖这 2 个方法来控制状态栏行为,并为您的应用程序返回适当的值(有关所有可能的值,请参阅文档参考,它有明确的解释)。
要控制应用程序启动期间的行为(显示的第一个控制器),请在项目设置 -> 下设置显示/隐藏一般->部署信息
请注意,iOS 7 仅支持单一外观样式(UIStatusBarStyleLightContent),所有其他样式均已弃用!
因此,您可以使用按钮轻松打开/关闭栏 - 尽可能灵活!
例如,向 viewController 添加一个按钮和一个 bool @property 'isStatusBarHidden' 使用以下代码通过动画打开/关闭栏。
您可以对首选动画执行相同的操作
高级注释:如果您想为@property'isStatusBarHidden'设置默认值,则需要在'initWithCoder'(使用Storyboards时调用)中执行此操作,而不是在viewDidLoad中。原因是“prefersStatusBarHidden”和“preferredStatusBarUpdateAnimation”在“viewDidLoad”之前调用
Here's a full iOS 7 compliant solution (not iOS 6 compatible though, as too many things have changed)
from the Apple doc ‘ : Information Property List Key Reference’ :
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.
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.
1) Globaly show/hide the status bar all of your app's viewControllers
so first the full answer to your question, to make a single, global show/hide setting for all of your apps 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.
step 2 : in project settings -> general -> deployment info, select 'show/hide' during application launch
that's it : now you can globally show or hide the status bar, compliant with iOS 7
2) Let all of your viewControllers have individual control over the status bar (= iOS 7 default)
step 1 : don't add the key, or add it, but set it to YES, to get the iOS 7 default behaviour
step 2 : in each viewController you can now determine if you show/hide the statusbar by overriding :
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).
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 !
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.
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'
您是否已经检查过在 Info.plist 中将
UIStatusBarHidden
设置为YES
是否有效?请参阅文档:<一href="http://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW15 ">http://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW15
这将在应用程序启动时隐藏状态栏。
Have you already checked if setting
UIStatusBarHidden
toYES
in 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
This will hide the status bar on application start.