Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide status bar while scrolling

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?

like image 726
jmcastel Avatar asked Oct 04 '14 21:10

jmcastel


Video Answer


2 Answers

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

like image 149
Yariv Nissim Avatar answered Sep 19 '22 13:09

Yariv Nissim


This is fixed problem for in Xcode 6.1

navigationController?.navigationBar.hidden = true

like image 34
Ali Raza Avatar answered Sep 19 '22 13:09

Ali Raza