1

I have a view controller that hides both navigationBar and statusBar. When the viewController pushes to a new viewController, where I want to show both navigationBar and statusBar, the result is like this:

enter image description here

In viewDidLoad, I do this:

self.navigationController?.navigationBar.barStyle = .default
self.navigationController?.setNavigationBarHidden(false, animated: false)
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)

If I tap on one of the tab items in my application, and then return back to the same tab that shows the view controller, the navigationBar is shown correctly without the black bar:

enter image description here

Any idea how I can show the navigationBar correctly?

Ivan C Myrvold
  • 680
  • 7
  • 23

1 Answers1

1

Here's how I do it:

Navigation Bar (set this in every view controller)

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.isNavigationBarHidden = true
}

Status Bar (set this in every view controller)

override var prefersStatusBarHidden: Bool {
    return true
}

Obviously, set true/false as needed. By doing this in every view controller you are insuring things behave the way you want (true == hide).

  • I tried your solution by returning true in `prefersStatusBarHidden` in the first viewController, but this didn't hide the status bar. I have to call `UIApplication.shared.setStatusBarHidden` for it to be hidden. – Ivan C Myrvold Dec 19 '16 at 15:41
  • Huh. It works for me. It won't work on a launch screen - that screen is extremely limited in what you can do. I also assume you've commented out all other code (maybe even in AppDelegate also) related to status bar behavior. –  Dec 19 '16 at 15:47