Strange constraints behaviour on iPad

六眼飞鱼酱① 提交于 2019-11-26 18:37:55

问题


I try to do one of the simples things ever and get a strange result.

I have a UIViewController with one UIImageView inside

I set the constraints like follow

And I get the following result

My questions are

  1. Why I get a padding on the left and right side? To remove that padding I have to use a constrains from -20 instead of -16 but then is the frame x - 4.

  2. Why Is the Vertical space to superview (top space) automatically -20

Does someone has this behaviour before and now how to solve it?

https://github.com/eikebartels/iPadTest https://github.com/eikebartels/iPadTest.git

Thanks in advance,

Eike


回答1:


The problem is that you've connected your constraints to the superview's margins. If you want to reach the edge of the superview you need to connect to the superview itself (with a constant of zero).

Note the word "margin" in the constraint description:

The problem with connecting to the margins is that you do not know what the margins will be when the app runs. It is a risky strategy. But you do know where the edges of the view will be, so if you want to match them, constrain to them, not to the margins. Use the margins only if you really want to match the margins, whatever they may be. For example, a constraint with a constant of 0 to a margin guarantees a nice space to the edge of the superview. But you do not want any space!



来源:https://stackoverflow.com/questions/27975552/strange-constraints-behaviour-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!