In a ViewController, which I presented modally, I did this:
override func prefersStatusBarHidden() -> Bool {
return true
}
This used
A late answer but if you need an alternative solution you can use this:
public func ShowStatusBar() {
let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
UIView.animate(withDuration: 0.3) {
statusBarWindow?.alpha = 1
}
}
public func HideStatusBar() {
let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
UIView.animate(withDuration: 0.3) {
statusBarWindow?.alpha = 0
}
}
In iOS 9, Xcode 7, Swift 2.0, it's back to how it was previously.
override func prefersStatusBarHidden() -> Bool {
return true
}
In fact Xcode will tell you that
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .None)
has been deprecated and that you should use the prefersStatusBarHidden method.
You can achieve this by simply overriding prefersStatusBarHidden
property in your ViewController as shown below :
override var prefersStatusBarHidden: Bool {
return true
}
This works for Swift 3/4.
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .None)
and when you want it back in a separate VC:
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .None)
For Swift 3 & Swift 4 it has changed to overriding a variable like this:
override var prefersStatusBarHidden: Bool {
return true
}
If you want to "Update" the state once the view controller is already being displayed, you will need to call:
setNeedsStatusBarAppearanceUpdate()
Please refer to the documentation.