Here is the Swift version (pre iOS9):
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
}
This also works (iOS7+):
override func prefersStatusBarHidden() -> Bool {
return true
}
You also need to call:
setNeedsStatusBarAppearanceUpdate()
in say viewDidLoad()
.
Note that if you use a SplitView controller, or some other container
view controller, you also need to have it return your class when its sent childViewControllerForStatusBarHidden
. One way to do this is have a public weak var for say statusController
, and return it in this overridden method.