DevC
DevC

Reputation: 7022

Show status bar with animation causes view to move up 20px so its under the status bar

I have a UIViewController that shows and hides the status bar. Hiding the status bar works no problem, however when I show the status bar using:

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

Causes the contents of the View to move up 20px so it ends up under the status bar. I dont know what else I can provide but this description, all that happens is when I hide the status bar, there is 20px of white space at the top where the status bar would be (this is what I want) but when I show the status bar the view moves up under the status bar (this is not what I want). The desire is to show and hide the status bar without effecting the UIViewController and its contents.

Upvotes: 0

Views: 1389

Answers (2)

moon4e
moon4e

Reputation: 316

I had the same issue. I managed to fix it in the Storyboard.

The top constrain for the view that was shifting up was set to Top Layout Guide. I changed it to point to Superview.Top and the view stopped moving.

To explicitly use Superview over top layout guide, you need to use the Pin (button on bottom left corner of storyboard) and before setting up the constrain uncheck "Constrain to margins"

Upvotes: 3

DevC
DevC

Reputation: 7022

I solved this by removing auto-layout on this ViewController and manually set the views layout in :

-(void)viewDidLayoutSubviews

Seems to solve the issue. Cheers to @ThatGuy for pushing me in the right directions.

Upvotes: 1

Related Questions