我添加一个“对齐"约束,但Xcode会添加"pin"约束自动布局 [英] I add a "align" constraint, but Xcode add a "pin" constraint autolayout
问题描述
添加约束后,可以在自动布局工具栏中的对齐"按钮或固定"按钮之间进行选择.
When we add constraints, we have the choice between "Align" button in the auto layout toolbar or "Pin" button.
在情节提要中,如果我在滚动视图与其容器之间添加了新的对齐约束底边".
In my storyboard, if I add a new alignment constraint "Bottom edges" between a scrollview and his container.
此约束的图标是2个正方形和一条线.
The icon of this constraint is 2 squares and a line.
但是之后,在我的滚动视图的约束列表中,图标有所不同:
But after, in the list of constraints of my scrollview, the icon is different :
该图标是"Pin"图标.
The icon is a "Pin" icon.
我不明白为什么.
还有一个问题,我想这是有关的:对齐底部"和底部空间"有什么区别?
One more question, I think it's related : what is the difference between "Align bottom" and "Bottom space" ?
推荐答案
Pin 和 Align 只是抽象,可以使您更轻松地了解所设置的内容.实际上,约束是两个对象的属性之间的关系.您在Interface Builder中使用align或pin指定的内容将转换为NSLayoutConstraint
对象.
Pin and Align are just abstractions to make it easier to understand what you are setting up. In reality, a constraint is a relation between attributes of two objects. What you specify in Interface Builder with align or pin gets translated into an NSLayoutConstraint
object.
通过编程方式完成后,没有 pin 或 align 选项,您只是在指定对象及其属性(.Top
,.Bottom
,.CenterX
等),关系(.Equal
,.GreaterThanOrEqual
,.LessThanOrEqual
),一个常数和一个乘数.
When done programmatically, there is no pin or align option, you are just specifying the objects, their attributes (.Top
, .Bottom
, .CenterX
, etc.) , the relation (.Equal
, .GreaterThanOrEqual
, .LessThanOrEqual
), a constant, and a multiplier.
例如,这是如何对齐两个按钮的底部:
For example, here is how to align the bottoms of two buttons:
NSLayoutConstraint(item: button1, attribute: .Bottom, relatedBy: .Equal, toItem: button2, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
如果两个对象是同级对象,则它们的底部被视为对齐.如果一个对象是另一对象的子视图,则将其视为底部空间.两者只是一个视图的.Bottom
与另一视图的.Bottom
之间的关系.
If the two objects are siblings, then their bottoms are considered to be aligned. If one object is a subview of the other object, then it is considered to be Bottom Space. Both are just a relation between the .Bottom
of one view to the .Bottom
of the other view.
单击约束并在属性"检查器中查看时,您会看到用于创建NSLayoutConstraint
的值.
When you click on the constraint and view it in the Attributes Inspector, you see the values that are used to create the NSLayoutConstraint
.
这篇关于我添加一个“对齐"约束,但Xcode会添加"pin"约束自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!