iPad上的奇怪行为的约束 [英] Strange constraints behaviour on iPad

查看:215
本文介绍了iPad上的奇怪行为的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做的事情simples有史以来之一,并得到一个奇怪的结果。

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

我有一个UIImageView的一个UIViewController内

I have a UIViewController with one UIImageView inside

我喜欢设置后续的约束

和我得到以下结果。

我的问题是


  1. 为什么我上左边和右边填充?要删除填充我不得不使用一个约束-20而不是-16,但随后是帧x - 4。

  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.

为什么是垂直空间,上海华(顶部空间)自动-20

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

由于提前,

埃克

推荐答案

的问题是,您将您的约束到上海华的的利润的。如果你想到达上海华你需要连接到上海华的本身的(为零的常数)。

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:

与连接到利润的问题是,你不知道应用程序运行时的利润将是什么。这是一个冒险的策略。但是,你知道哪里有观点的边缘会,所以如果你想与它们匹配,约束到的他们的,而不是边缘。使用边距只有当你真的想匹配的利润,不管他们可能。例如,以0至余量恒定约束保证了很好的空间到上海华的边缘。但你不希望任何空间!

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!

这篇关于iPad上的奇怪行为的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆