On iOS8, displaying my app in landscape mode will hide the status bar but on iOS 7 the status bar is displayed on both orientations

26,987

Solution 1

Try this

Add below code in didRotateFromInterfaceOrientation

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

EDIT
NO NEED TO WRITE CODE IN ALL VIEW CONTROLLER
Set View controller-based status bar appearance to NO in plist and add below code in root view controller's viewDidLoad

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

Demo project
https://www.dropbox.com/s/uumneidk4wom5md/demoStatusBar.zip?dl=0

Solution 2

To display status bar in landscape mode in ios 8, try following method

- (BOOL)prefersStatusBarHidden {
    return NO;
}

Swift version

override func prefersStatusBarHidden() -> Bool {
    return false
}

Swift 3, Xcode 8, iOS 10, /* ViewController.swift */

override var prefersStatusBarHidden: Bool {
        return false
    }

Solution 3

Jageen's solution is probably the best, with just one minor change i.e. instead of using viewDidLoad, it's better to use application:didFinishLaunchingWithOptions:.

It's basically a two step process:

1). Set "View controller-based status bar appearance" to NO, in your project's Info.plist file.

2). Force the status bar hidden status to NO, in application:didFinishLaunchingWithOptions:, using the following code:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

And, voila!

Note: It's important to use both the setStatusBarHidden:withAnimation statements above, to force the status bar hidden state.

Solution 4

It's not an issue but a feature of an iOS 8. The status bar will be hidden in landscape mode in iOS 8, even Apple's applications also having same behaviour.

Solution 5

I had the same issue! Fixed by addicting this to viewDidLoad

  [self setNeedsStatusBarAppearanceUpdate];

And this to implementation itself

-(BOOL)prefersStatusBarHidden{
    return NO;
}
Share:
26,987
Tim Nuwin
Author by

Tim Nuwin

Updated on July 09, 2022

Comments

  • Tim Nuwin
    Tim Nuwin almost 2 years

    I want the status bar to be displayed in both orientations in iOS 8; it's being displayed properly in iOS 7.

    navigationController.isNavigationBarHidden returns NO.

    Why is iOS 8 doing this?

  • Harshit Gupta
    Harshit Gupta over 9 years
    we will have to write this code in every view controller, right?
  • Harshit Gupta
    Harshit Gupta over 9 years
    we will have to write this code in every view controller, right?
  • Harshit Gupta
    Harshit Gupta over 9 years
    thanks for the replay and demo project. In my case my root view controller keep on changing all the time. So will have to write in every root view controller
  • Jageen
    Jageen over 9 years
    just try to code in once first root view controller, may help
  • Mustafa
    Mustafa over 9 years
    This appears to be the best solution, with one minor suggested change i.e. use application:FinishLaunchingWithOptions: to force the status bar hidden state.
  • Jageen
    Jageen over 9 years
    @Mustafa nice suggestion
  • Aleksejs Mjaliks
    Aleksejs Mjaliks over 9 years
    A note: You don't need to call [UIApplication sharedApplication] in application:didFinishLaunchingWithOptions:, because there is a method argument application. Thus, just call [application setStatusBarHidden:...].
  • xevser
    xevser over 8 years
    For Swift : override func prefersStatusBarHidden() -> Bool { return false; }
  • Bartłomiej Semańczyk
    Bartłomiej Semańczyk almost 8 years
    Will it work with trait collection did change also? Really? With iOS 9?;) please confirm this...
  • Bartłomiej Semańczyk
    Bartłomiej Semańczyk almost 8 years
    It is deprecated since iOS 9.
  • Gienadij Mackiewicz
    Gienadij Mackiewicz almost 6 years
    It works only if you has set View controller-based status bar appearance in your plist file to YES.