iOS 8 adds a super new cool feature: hiding the navigation bar when user is scrolling.
This with a single line in viewDidload
:
navigationController?.hidesBarsOnSwipe = true
Cool, isn't it?
But now I have a little problem: when the navigation bar is hidden, the status bar is still here and overlaps content, which is ugly.
What should I do to make it hidden when the navigation bar is hidden?
Override the following methods on UIViewController:
extension MyViewController {
override func prefersStatusBarHidden() -> Bool {
return barsHidden // this is a custom property
}
// Override only if you want a different animation than the default
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .slide
}
}
Update barsHidden
somewhere in the code and call
setNeedsStatusBarAppearanceUpdate()