How do you hide the status bar in ios 9?
This is now deprecated:
[UIApplication sharedApplication] setStatusBarHidden:YES];
答案 0 :(得分:81)
Swift-3
override var prefersStatusBarHidden: Bool {
return true
}
I got the Information From Here
Change func
to var
Delete ()
Change ->
to :
This works because a computed variable has a getter function, so the function you were implementing before simply turns into the getter function
2016 onwards: simple Thing like
On your info.plist add the following two property for statusBar Hidden
View controller-based status bar appearance (Boolean: NO)
Status bar is initially hidden (Boolean: YES)
By Source
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
or
Old answers ! ...
add application.statusBarHidden
in 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 this View controller-based status bar appearance
set NO
View controller-based status bar appearance = NO
viewcontroller based hidden set
Add method in your view controller.
Objective -C
- (BOOL)prefersStatusBarHidden {
return YES;
}
Swift upto 2
override func prefersStatusBarHidden() -> Bool {
return true
}
(GOOD) 2016.5.17 in iOS 9.0 worked nicely.
Updated Answer
For 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
}
答案 1 :(得分:16)
添加以下两个属性。
View controller-based status bar appearance (NO)
Status bar is initially hidden (YES)
答案 2 :(得分:7)
I know that the documentation of setStatusBarHidden:
does not mention on what use instead. But the header of UIApplication
does.
// 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.
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;
}
答案 3 :(得分:6)
以下是如何轻松返回 iOS 9 + 和 Swift 3 + 状态栏可见性的控件:
View controller-based status bar appearance
值YES
添加到Info.plist
。将此变量添加到视图控制器:
private var isStatusBarHidden = false {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}
覆盖prefersStatusBarHidden
属性:
override var prefersStatusBarHidden: Bool {
return isStatusBarHidden
}
就是这样。现在,您可以随时拨打isStatusBarHidden = true
和isStatusBarHidden = false
。
答案 4 :(得分:2)
一种简单的方法是根据您的需求将应用程序的windowLevel
设置为normal或statusBar,然后启动
Objective-C
隐藏状态栏
UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelStatusBar;
显示状态栏
UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelNormal;
还添加具有布尔值NO的Key
(基于控制器的视图状态栏外观)。
答案 5 :(得分:1)
如果出于某种原因,您需要View controller-based status bar appearance
等于YES
(例如将状态栏保持为白色)
在AppDelegate的didFinishLaunchingWithOptions
方法或设置navigationController的任何地方:
yourNavigationController.navigationBar.barStyle = .black
然后使用alex-staravoitau的精彩答案,并在您隐藏状态栏的任何地方添加此代码:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
我不确定这是否是实现此结果的正确方法,但它对我有用,我希望它也可以帮助其他人:)
答案 6 :(得分:0)
在大多数iOS中都可以使用。我已经使用iOS 10进行了测试。