Top space on device rotation

860 Views Asked by At

I have the following constraints on my UIView in portrait mode:

Portrait

And landscape:

Landscape

This is screenshot of the ViewController when I open it first time:

Portrait 1

Top space is OK.

Then I'm rotating the device to landscape:

Landscape

Do you see that white space on the top?

And when I'm rotating it back to landscape, the space still stays:

Portrait 2

Why and how to fix it?

3

There are 3 best solutions below

0
On BEST ANSWER

Try to uncheck Adjust scrollview insets Of viewcontroller attribute

enter image description here

Source Of Image: Here

2
On

You might have set TopConstraint of your view With margin.

Uncheck box for Add to Margin.

enter image description here

0
On

Considering black view about the imageview which contains Back button is a UIView (says, viewNav)

Constraints for viewNav:

enter image description here

if you'r changing the height of viewNav of rotation then use size classes as see below and click on landscape option. Now select your navView and click on height constraint and give c-c constraint like this

enter image description here enter image description here

Constraints for UiImageView:

enter image description here

If you'r image covers the complete screen the give bottom constraint as 0.

This fixes every thing.

If you are using native navigationBar then you there will be no viewNav and now constraint for image will be

enter image description here

On giving top constraint, don't forget to select use standard value for top constraint then enter 64. Bottom and height is according to your need whatever you prefer.