【发布时间】:2017-09-21 20:10:17
【问题描述】:
这是我的代码:
let b = NSLayoutConstraint(item: some, attribute: fromAttribute, relatedBy: NSLayoutRelation.equal, toItem: some2, attribute: toAttribute, multiplier: multiplier, constant: -5)
b.isActive = true
self.layoutIfNeeded()
print(b.constant)
print(some.constraints.first(where: {$0.constant == -5 }))
这是我的印刷品:
-5.0
nil
如何在代码中恢复该约束?为什么它打印出零?我想稍后为约束的常量设置动画。谢谢。
【问题讨论】:
-
使其成为类级别的变量/属性,而不是局部范围的变量。
-
@DonMag 您认为会有所不同吗?你的意思是变量 B 类级别的变量对吗?
-
约束已添加到
some,您现在如何?请向我们展示视图层次结构。如果some2不是some的子视图,那么这不起作用。
标签: ios swift autolayout nslayoutconstraint