Ios NSLAYOUTACHOR和约束标识符
如果我要使用NSLayoutConstraint,我会首先初始化约束,比如:Ios NSLAYOUTACHOR和约束标识符,ios,autolayout,nslayoutconstraint,Ios,Autolayout,Nslayoutconstraint,如果我要使用NSLayoutConstraint,我会首先初始化约束,比如: let myConstraint = NSLayoutConstraint(...) 然后我会添加这样的标识符: myConstraint.identifier = "myIdentifier" 然后我会激活: myConstraint.active = true 是否有方法将标识符添加到使用nslayoutachor类创建的约束中?我查看了文档,但是没有找到任何东西。是的,您可以。苹果的文档说: NSLAYOU
let myConstraint = NSLayoutConstraint(...)
然后我会添加这样的标识符:
myConstraint.identifier = "myIdentifier"
然后我会激活:
myConstraint.active = true
是否有方法将标识符添加到使用
nslayoutachor
类创建的约束中?我查看了文档,但是没有找到任何东西。是的,您可以。苹果的文档说:
NSLAYOUTACHOR类是一个工厂类,用于使用fluent API创建NSLayoutConstraint对象。使用这些约束可以使用“自动布局”以编程方式定义布局
因此,nslayoutachor
只是一个为您创建约束的类,该类的实例不是约束。
例如:
subview.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor).identifier = "myIdentifier"
但是,在我看来,我无法在一行中指定标识符并激活约束。如果要添加标识符,我必须将其分配给常量(或变量),然后激活它。使用
NSLayoutConstraint
时仍然如此。