I'm trying to change a constraint at a push of a button.
@IBAction func firstButton(_ sender: Any) {
someTableView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -16).isActive = false
someTableView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -46).isActive = true
someTableView.updateConstraints()
}
@IBAction func secondButton(_ sender: Any) {
someTableView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -46).isActive = false
someTableView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -16).isActive = true
someTableView.updateConstraints()
}
I have an error once both constraints are active. They won't deactivate:
[LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it.
[shortened].bottom == [shortened].bottom - 46 (active)>
[shortened].bottom == [shortened].bottom - 16 (active)>
Will attempt to recover by breaking constraint
[shortened].bottom == [shortened].bottom - 16 (active)>
edit:
Everyone had the correct answer here, and it helped me greatly. I just accepted the one that had example code.
Thanks guys!