我有两个UI布局约束,它们在设计上相互冲突.一次只能有一个活跃. 
  
 
在UIViewController的方法updateConstraintsIfNeeded中,我有以下代码在两个约束之间切换,具体取决于数据模型的状态.
override func updateConstraintsIfNeeded() {
    super.updateConstraintsIfNeeded()
    if question?.thumbURL != nil {
        showAttachmentConstraint.active = true
        hideAttachmentConstraint.active = false        
    } else {
        showAttachmentConstraint.active = false
        hideAttachmentConstraint.active = true
    }
} 
 这项工作按计划进行,但我在调试输出中得到了这个熟悉的警告:
Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don’t want. …
显然当执行语句showAttachmentConstraint.active = true时,它暂时与当时仍处于活动状态的hideAttachmentConstraint冲突.
是否可以将此切换操作原子化?我希望在UITableView中有类似beginUpdate和endUpdate的东西.
解决方法
 您可以将其中一个冲突约束的优先级更改为999而不是1000.因此您在设计时甚至没有任何问题.