0

I want to show the status bar on portrait mode only, when I rotate the screen the status bar hides as intended but if I push / show a new View Controller the status bar appears again.

I've tried the following without success:

  • Setting View controller-based status bar appearance to NO in the info.plist file
  • Using setNeedsStatusBarAppearanceUpdate() on self and on NavigationController
  • Setting prefersStatusBarHidden: Bool to true
  • Also tried UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.none)
  • Also extending NavigationController. seen here

Any help will be appreciated. Thanks.

PerroVerde
  • 49
  • 8
  • 1
    Possible duplicate of [How to hide status bar of a single view controller in iOS 9?](http://stackoverflow.com/questions/35028262/how-to-hide-status-bar-of-a-single-view-controller-in-ios-9) – Pochi Mar 16 '17 at 12:23
  • 1
    Nope, they suggest the same things that i've tried and aren't working for me. Thanks anyway! – PerroVerde Mar 16 '17 at 14:32

1 Answers1

0

Try Following Code

override var prefersStatusBarHidden: Bool {

    if UIDevice.current.orientation.isPortrait{
        return false
    }
    return true
}
Nayan Dave
  • 1,078
  • 1
  • 8
  • 30
  • 1
    Could you explain a little how this solves the question in addition to the code? Thanks – Carl Poole Mar 16 '17 at 12:58
  • I have written this code in main viewController Also set View controller-based status bar appearance to NO in the info.plist When i back to my main viewController after navigation its work fine according to landscape and portrait mode – Jalpa Jani Mar 16 '17 at 13:07
  • Hi @JalpaJani , this is what I'm doing but I did shorten my question with just 'prefersStatusBarHidden: Bool to true' for reading purposes, but thanks anyway! – PerroVerde Mar 16 '17 at 14:24