在 ios 9 中隐藏状态栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32965610/
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
Hide the status bar in ios 9
提问by cdub
How do you hide the status bar in ios 9?
你如何在ios 9中隐藏状态栏?
This is now deprecated:
现在已弃用:
[UIApplication sharedApplication] setStatusBarHidden:YES];
回答by Anbu.Karthik
Swift-3
斯威夫特-3
override var prefersStatusBarHidden: Bool {
return true
}
I got the Information From Here
我从这里得到信息
Change
func
tovar
Delete
()
Change
->
to:
更改
func
为var
删除
()
更改
->
为:
This works because a computed variable has a getter function, so the function you were implementing before simply turns into the getter function
这是有效的,因为计算变量有一个 getter 函数,所以你之前实现的函数只是变成了 getter 函数
2016 onwards: simple Thing like
2016 年起:简单的事情就像
On your info.plist add the following two property for statusBar Hidden
在 info.plist 上为 statusBar Hidden 添加以下两个属性
View controller-based status bar appearance (Boolean: NO)
查看基于控制器的状态栏外观(布尔值:NO)
Status bar is initially hidden (Boolean: YES)
状态栏最初是隐藏的(布尔值:YES)
By Source
按来源
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
or
或者
Old answers ! ...
旧答案!...
add
application.statusBarHidden
indidFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. application.statusBarHidden = YES; return YES; }
添加
application.statusBarHidden
在didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. application.statusBarHidden = YES; return YES; }
and add
并添加
in
info.plist
add thisView controller-based status bar appearance
setNO
View controller-based status bar appearance = NO
在
info.plist
添加这个View controller-based status bar appearance
集合NO
View controller-based status bar appearance = NO
viewcontroller based hidden set
基于视图控制器的隐藏集
Add method in your view controller.
在视图控制器中添加方法。
Objective -C
目标-C
- (BOOL)prefersStatusBarHidden {
return YES;
}
Swift upto 2
快速到 2
override func prefersStatusBarHidden() -> Bool {
return true
}
(GOOD) 2016.5.17 in iOS 9.0 worked nicely.
(好)iOS 9.0 中的 2016.5.17 运行良好。
Updated Answer
更新答案
- Go to Info.plist file
- Hover on one of those lines and a (+) and (-) button will show up.
- Click the plus button to add new key
- Type in start with capital Vand automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
- Set the VALUE to "NO"
- Go to you AppDelegate.m for Objective-C (for swift language: AppDelegate.swift)
- Add the code, inside the method
- 转到 Info.plist 文件
- 将鼠标悬停在其中一行上,将显示 (+) 和 (-) 按钮。
- 单击加号按钮添加新密钥
- 输入以大写 V 开头,第一个选项会自动成为View controller-based status bar appearance。将其添加为 KEY。
- 将值设置为“否”
- 转到你的 AppDelegate.m for Objective-C(对于 swift 语言: AppDelegate.swift)
- 在方法内添加代码
For Objective-C:
对于 Objective-C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];
return YES;
}
For Swift:
对于斯威夫特:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
application.statusBarHidden = true
return true
}
回答by Jamil
in info.plist add the following two property.
在 info.plist 中添加以下两个属性。
View controller-based status bar appearance (NO)
Status bar is initially hidden (YES)
回答by rckoenes
I know that the documentation of setStatusBarHidden:
does not mention on what use instead. But the header of UIApplication
does.
我知道文档setStatusBarHidden:
没有提到使用什么。但标题UIApplication
确实如此。
// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]");
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use -[UIViewController prefersStatusBarHidden]");
Here is stated that you should use the prefersStatusBarHidden
on UIViewController
and use view controller based statusbar styles.
这里声明您应该使用prefersStatusBarHidden
onUIViewController
并使用基于视图控制器的状态栏样式。
All you need to do now is configure whether the view controller needs to show of hide the status bar. Like so :
您现在需要做的就是配置视图控制器是否需要显示或隐藏状态栏。像这样:
- (BOOL)prefersStatusBarHidden {
return YES;
}
回答by Andrey Gordeev
Here's how do you easily return a control over status bar visibility for iOS 9+and Swift 3+:
以下是如何轻松返回对iOS 9+和Swift 3+状态栏可见性的控制:
- Add
View controller-based status bar appearance
key withYES
value toInfo.plist
. Add this variable to the view controller:
private var isStatusBarHidden = false { didSet { setNeedsStatusBarAppearanceUpdate() } }
Override
prefersStatusBarHidden
property:override var prefersStatusBarHidden: Bool { return isStatusBarHidden }
- 将
View controller-based status bar appearance
带YES
值的键添加到Info.plist
. 将此变量添加到视图控制器:
private var isStatusBarHidden = false { didSet { setNeedsStatusBarAppearanceUpdate() } }
覆盖
prefersStatusBarHidden
属性:override var prefersStatusBarHidden: Bool { return isStatusBarHidden }
That's it. Now you are able to call isStatusBarHidden = true
and isStatusBarHidden = false
whenever you want.
就是这样。现在,您可以打电话isStatusBarHidden = true
和isStatusBarHidden = false
只要你想。
回答by daris mathew
An easy approach would be to set the windowLevel
of the Application to be either normal or statusBar based on your needs, so to start
一个简单的方法是windowLevel
根据您的需要将应用程序的设置为 normal 或 statusBar,因此开始
Objective-C
目标-C
To Hide the Status Bar
隐藏状态栏
UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelStatusBar;
To Show the Status Bar
显示状态栏
UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelNormal;
Also add the Key
(View controller-based status bar appearance) with boolean value NO.
还添加布尔值 NO Key
(基于视图控制器的状态栏外观)。
回答by budidino
If for some reason you need View controller-based status bar appearance
equal to YES
(for example to keep status bar white)
如果出于某种原因您需要View controller-based status bar appearance
等于YES
(例如保持状态栏为白色)
on AppDelegate's didFinishLaunchingWithOptions
method or wherever you setup your navigationController:
在 AppDelegate 的didFinishLaunchingWithOptions
方法或您设置导航控制器的任何地方:
yourNavigationController.navigationBar.barStyle = .black
then use alex-staravoitau's awesome answer and add this code wherever you'll be hiding the status bar:
然后使用alex-staravoitau的很棒的答案,并在隐藏状态栏的任何地方添加此代码:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I'm not sure if this is the right way to achieve this result, but it worked for me and I hope it helps someone else too :)
我不确定这是否是实现此结果的正确方法,但它对我有用,我希望它也能帮助其他人:)
回答by emraz
In most of the iOS it will work. I have tested with iOS 10.
在大多数 iOS 中它都可以工作。我已经用 iOS 10 测试过了。
- Open info.plist
- "View controller-based status bar appearance" set to NO
- "Status bar is initially hidden" set to YES
- Done
- 打开 info.plist
- “基于视图控制器的状态栏外观”设置为 NO
- “状态栏最初是隐藏的”设置为“是”
- 完毕