Law*_*413 5 ios nslayoutconstraint swift
我有一个奇怪的问题。我想在某些条件下更改约束,但removeConstraint不起作用。约束不会被删除。
这是代码:
backButton.translatesAutoresizingMaskIntoConstraints = false
view.removeConstraint(constLabelTop)
let constNew = NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: backButton, attribute: .CenterY,multiplier: 1, constant: 0)
view.addConstraint(constNew)
Run Code Online (Sandbox Code Playgroud)
该约束constLabelTop是设置上方label几个点顶部的约束backButton。为什么不起作用?
新约束与旧约束发生冲突,并且backButton被压缩。
我也尝试backButton.removeConstraint过,也没有用。
尝试这个:
backButton.translatesAutoresizingMaskIntoConstraints = false
constLabelTop.active = false
NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: backButton, attribute: .CenterY,multiplier: 1, constant: 0).active = true
self.view.layoutIfNeeded()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
931 次 |
| 最近记录: |