我有两个UI布局约束,它们在设计上相互冲突.一次只能有一个活跃.
在UIViewController's方法中updateConstraintsIfNeeded,我有以下代码在两个约束之间切换,具体取决于数据模型的状态.
override func updateConstraintsIfNeeded() {
super.updateConstraintsIfNeeded()
if question?.thumbURL != nil {
showAttachmentConstraint.active = true
hideAttachmentConstraint.active = false
} else {
showAttachmentConstraint.active = false
hideAttachmentConstraint.active = true
}
}
Run Code Online (Sandbox Code Playgroud)
这项工作按计划进行,但我在调试输出中得到了这个熟悉的警告:
无法同时满足约束.可能至少下列列表中的一个约束是您不想要的约束....
显然,当语句showAttachmentConstraint.active = true执行时,它暂时与hideAttachmentConstraint当时仍处于活动状态的冲突相冲突.
是否可以将此切换操作原子化?我希望能有像beginUpdate和endUpdate在UITableView.
| 归档时间: |
|
| 查看次数: |
1266 次 |
| 最近记录: |