如何在 iOS 中隐藏状态栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12661031/
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
How to hide a status bar in iOS?
提问by Arkady
I can hide a status bar in my app:
我可以在我的应用中隐藏状态栏:
- (void)viewDidLoad{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidLoad];
}
When I chose my launch image and start it first time, it's status bar over a picture. How can I hide this?
当我选择我的启动图像并第一次启动它时,它是图片上方的状态栏。我怎样才能隐藏这个?
回答by Charan
You need to add this code in your AppDelegate file, not in your Root View Controller
您需要将此代码添加到您的 AppDelegate 文件中,而不是在您的根视图控制器中
Or add the property Status bar is initially hiddenin your plist file
或者添加属性状态栏最初隐藏在您的 plist 文件中
Folks, in iOS 7+
伙计们,在iOS 7+ 中
please add this to your info.plist file, It will make the difference :)
请将其添加到您的 info.plist 文件中,它会有所作为 :)
UIStatusBarHidden UIViewControllerBasedStatusBarAppearance
UIStatusBarHidden UIViewControllerBasedStatusBarAppearance
For iOS 11.4+ and Xcode 9.4 +
对于 iOS 11.4+ 和 Xcode 9.4+
Use this code either in one or all your view controllers
在一个或所有视图控制器中使用此代码
override var prefersStatusBarHidden: Bool { return true }
覆盖 var prefersStatusBarHidden: Bool { return true }
回答by Hardik Darji
Add the following code to your view controller:
将以下代码添加到您的视图控制器:
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
回答by Arkady
What helped me is this (changing plist file):
对我有帮助的是这个(更改 plist 文件):
- set Status bar is initially hidden = YES
- add row: View controller-based status bar appearance = NO
- 设置状态栏最初是隐藏的 = YES
- 添加行:查看基于控制器的状态栏外观 = NO
回答by Aleksandr Sis'ov
Put this code to your view controller in which you hide status bar:
将此代码放在隐藏状态栏的视图控制器中:
- (BOOL)prefersStatusBarHidden {return YES;}
回答by Alex Markman
In iOS 7 status bar appearance depends on UIViewController
as default. To hide status bar globally, in info.plist
use NO
value for UIViewControllerBasedStatusBarAppearance
key and use UIApplication
's setStatusBarHidden
method with YES
BOOL
value.
在 iOS 7 状态栏外观取决于UIViewController
默认。全局隐藏状态栏,info.plist
使用key 的NO
valueUIViewControllerBasedStatusBarAppearance
并使用valueUIApplication
的setStatusBarHidden
方法YES
BOOL
。
回答by Kursat Turkay
add this key key from dropdownlist in "info.plist" and voila you will no more see top bar that includes elements something like GSM,wifi icon etc.
从“info.plist”的下拉列表中添加这个键,瞧,您将不会再看到包含GSM、wifi图标等元素的顶部栏。
回答by Jaywant Khedkar
It's working for me ,
它对我有用,
Add below code into the info.plist file ,
将以下代码添加到 info.plist 文件中,
<key>UIStatusBarHidden</key>
<false/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Hopes this is work for some one .
希望这对某人有用。
回答by jeet.chanchawat
In info.plist
在 info.plist
View controller-based status bar appearance NO
Status bar is initially hidden YES
In view controller.m
在 view controller.m
- (BOOL) prefersStatusBarHidden
{
return YES;
}
回答by BuvinJ
I am supporting iOS 5, 6, & 7. My app is iPad only. I needed to use all of the following:
我支持 iOS 5、6 和 7。我的应用程序仅适用于 iPad。我需要使用以下所有内容:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
View Controller:
视图控制器:
- (BOOL)prefersStatusBarHidden{ return YES; }
Info.plist
信息表
<key>UIStatusBarHidden</key>
<string>YES</string>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<string>NO</string>
回答by codingrhythm
A complete solution in swift, in your view controller
快速的完整解决方案,在您的视图控制器中
// you can use your own logic to determine if you need to hide status bar
// I just put a var here for now
var hideStatusBar = false
override func preferStatusBarHidden() -> Bool {
return hideStatus
}
// in other method to manually toggle status bar
func updateUI() {
hideStatusBar = true
// call this method to update status bar
prefersStatusBarHidden()
}