I have two UI layout constraints that are conflicting with each other by design. Only one of could be active at a time.
In UIViewController's
method updateConstraintsIfNeeded
, I have the following code which toggles between the two constraints, depending on the state of a data model.
override func updateConstraintsIfNeeded() {
super.updateConstraintsIfNeeded()
if question?.thumbURL != nil {
showAttachmentConstraint.active = true
hideAttachmentConstraint.active = false
} else {
showAttachmentConstraint.active = false
hideAttachmentConstraint.active = true
}
}
This work as intended, but I got this familiar warning in the debug output:
Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. ...
Apparently when the statement showAttachmentConstraint.active = true
is executed, it temporarily conflicts with hideAttachmentConstraint
which is still active at that time.
Is it possible to make this toggle operation atomic? I'm hoping there is something like beginUpdate
and endUpdate
in UITableView
.