On iOS8, displaying my app in landscape mode will

2019-01-10 11:10发布

问题:

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?

回答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



回答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
    }


回答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.



回答4:

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

  [self setNeedsStatusBarAppearanceUpdate];

And this to implementation itself

-(BOOL)prefersStatusBarHidden{
    return NO;
}


回答5:

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.



回答6:

They are keeping us gainfully employed by giving us more work.

or...

They've made other changes which cause bits to take up more space than they used to. With iOS 7 and the advent of things like the "Top Layout Bar Guide", the easy availability of the status bar in the swipe down screen, reclaiming the status bar space to be usable and other little hints many people predicted the status bar might be getting phased out as a standard part of the UI.

There is also quite a bit of buzz about new device sizes due to the changes they've made in iOS 8 trying to make it easier to code for a bunch of different sizes.

It's pure speculation, but I don't think they landscape status bar will return in iOS 8.



回答7:

Swift 3

override func viewDidLoad() {
        super.viewDidLoad()
        UIApplication.shared.setStatusBarHidden(true, with: .none)
        UIApplication.shared.setStatusBarHidden(false, with: .none)
///
    }

and add inside Info.plist this:

UIViewControllerBasedStatusBarAppearance boolean value NO



回答8:

Swift 3 (As of June 2, 2017)

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear()
    self.setNeedsStatusBarAppearanceUpdate()
}

override var prefersStatusBarHidden : Bool {
    return false
}


回答9:

We fixed it by following the above steps and making sure that landscape left and right are both enabled.

Under Project/Target/Deployment Info



回答10:

We solved this by forcing an orientation change unseen by the user. In the first view controller that loads, add:

- (void)viewWillAppear:(BOOL)animated
{
    NSNumber *orientationLeft = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    NSNumber *orientationRight = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
    [[UIDevice currentDevice] setValue:orientationLeft forKey:@"orientation"];
    [[UIDevice currentDevice] setValue:orientationRight forKey:@"orientation"];
}