Modally presented UIViewController hides status bar, but doesn't show it again on dismiss

2.9k views Asked by At

So I have a view controller modalVC that I am instantiating from a storyboard and presenting modally via [self presentViewController:modalVC animated:YES completion:nil].

The problem is that when the modal view is displayed, the status bar is hiding (which I actually want, even though I'm making no explicit instruction to do so), but when the modal controller is dismissed (via [self dismissViewControllerAnimated:YES completion:nil]), the status bar is remaining hidden.

I reiterate, I'm not to my knowledge making any explicit command to hide the status bar. None of my view controllers are overriding prefersStatusBarHidden, and nowhere am I calling setStatusBarHidden. I assume it's just the default modal presentation doing this.

But why is my status bar not reappearing?

3

There are 3 answers

0
Doro On BEST ANSWER

dismiss the modal using dismissViewControllerAnimated:YES, and call

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

before

dismissViewControllerAnimated:YES

to make sure the bar is drawn in the correct location (it could happen when you set wantsFullScreenLayout to YES on your modal view )

0
devios1 On

I'm stupid. It turns out I was setting statusBarHidden = YES when the modal view was appearing.

Crisis averted!

0
SudoPlz On

For others that may end up here banging their heads on the wall for hours, trying to figure why their status bar get's hidden, keep in mind that if supportedInterfaceOrientations returns an invalid orientation, say goodbye to your status bar on iPhone X devices.

In our case supportedInterfaceOrientations returned 0 (which is not a valid UIInterfaceOrientationMask orientation), but no errors no nothing. The only side effect was that the status bar was getting hidden after we presented another view controller modally.

I hope that saves someone.