自动布局:为什么这些相同的约束有什么不同? [英] Autolayout: why are these same constrains different?

查看:115
本文介绍了自动布局:为什么这些相同的约束有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习自动布局。目前,我正在添加一个简单的约束条件:0像素缘的景色,它的SuperView之间

I'm learning autolayout. I'm currently adding a simple constraint: 0px margin between a view and it superview.

显然,有两种方式添加此约束

Apparently, there are two ways to add this constraint:

首先,点击你的厦门国际银行的编辑器右下方的按钮,选择左边空白处,点击的添加n个约束的,因为在给定的截图:

First, click on the lower right button of your xib editor, select the left margin and click add n constraints, as in the given screenshot:

这是第一个约束性。它有一个16像素恒缘:结果

Here's the first constrain properties. It has a 16px constant margin:

二的方式,选择在X code菜单:编辑>针>引领空间上海华:结果

Second way, select in Xcode menu: Editor > Pin > Leading space to superview:

现在,我的约束有0像素,但它也能工作:视图很好地适应根据它的父

Now, my constraint has 0px, but it works too: the view is well adapted according to its superview

下面是我的第二个约束属性:结果

Here's my second constraint properties:

第一个问题:为什么我的第一个约束左,右页边距为 16像素?我工作的一个全新的项目!如果我设置0像素,周围有我的看法有些额外的空间!

First question: why my first constraint left and right margin are 16px? I'm working on a brand new project! If I set 0px, there is some extra space around my view!

第二个问题:的是这两个约束之间的区别?什么是最好的方法是什么?

Second question: what is the difference between these two constraints? What is the best method?

感谢

推荐答案

您已经给出了答案。成为制约上海华是不一样的成为制约上海华的保证金。

You've already given the answer. A constraint to the superview is not the same as a constraint to the superview's margin.

如果你想想你是如何形成这些限制的在code 的这可能是最容易的。下面是可以使用的属性:

It might be easiest if you think about how you'd form these constraints in code. Here are the attributes you can use:

<一个href=\"https://developer.apple.com/Library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/c/tdef/NSLayoutAttribute\" rel=\"nofollow\">https://developer.apple.com/Library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/c/tdef/NSLayoutAttribute

正如你所看到的,有右的和RightMargin。钉扎子视图的右边缘到它的父的权利是不一样的,因为它寄托于它的父的RightMargin。

As you can see, there is both Right and RightMargin. Pinning a subview's right edge to its superview's Right is not the same as pinning it to its superview's RightMargin.

这篇关于自动布局:为什么这些相同的约束有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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