问题
I have the following constraints on my UIView in portrait mode:
And landscape:
This is screenshot of the ViewController when I open it first time:
Top space is OK.
Then I'm rotating the device to landscape:
Do you see that white space on the top?
And when I'm rotating it back to landscape, the space still stays:
Why and how to fix it?
回答1:
Try to uncheck Adjust scrollview insets
Of viewcontroller attribute
Source Of Image: Here
回答2:
You might have set TopConstraint of your view With margin.
Uncheck box for Add to Margin.
回答3:
Considering black view about the imageview which contains Back button is a UIView (says, viewNav)
Constraints for viewNav:
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
Constraints for UiImageView:
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
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.
来源:https://stackoverflow.com/questions/41184084/top-space-on-device-rotation