Strange constraints behaviour on iPad

后端 未结 1 1061
孤城傲影
孤城傲影 2020-12-04 03:16

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

I have a UIViewController with one UIImageView inside

相关标签:
1条回答
  • 2020-12-04 03:52

    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:

    enter image description here

    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!

    0 讨论(0)
提交回复
热议问题