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

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

问题描述

我尝试做一件最简单的事情,但得到了一个奇怪的结果.

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

我有一个 UIViewController,里面有一个 UIImageView

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/iPadTesthttps://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).

注意约束描述中的margin"一词:

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天全站免登陆