Hide status bar while scrolling Hide status bar while scrolling swift swift

Hide status bar while scrolling


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 callsetNeedsStatusBarAppearanceUpdate()


This is fixed problem for in Xcode 6.1

navigationController?.navigationBar.hidden = true


I am basing this answer on some comments on this post, which are speculation. I am not sure if this will work, because Apple does not give us any direct way or delegate method for when the navigation bar hides.

Subclass UINavigationBar as NavigationBar. Add a property observer to its hidden property like so:

var hidden: Bool{didSet{    UIApplication.sharedApplication().setStatusBarHidden(self.hidden, animation: .Slide)}}

You want to then go to your viewDidLoad method in your main view controller, and set your self.navigationBar property (or self.navigationController.navigationBar, not sure which one) to an instance of your new NavigationBar class.

Note that I cannot test this right now, let me know how/if this works.