我正尝试按一下按钮更改约束。
@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()
}
一旦两个约束都处于事件状态,我就会出错。他们不会停用:
[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)>
编辑:
这里每个人都有正确答案,对我帮助很大。我刚刚接受了带有示例代码的那个。
谢谢大家!
最佳答案
每次点击都会引起新的冲突
var botCon:NSLayoutConstraint!
//
botCon = someTableView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -16)
botCon.isActive = true
//
@IBAction func firstButton(_ sender: Any) {
botCon.constant = -46
self.view.layoutIfNeeded()
}
@IBAction func secondButton(_ sender: Any) {
botCon.constant = -16
self.view.layoutIfNeeded()
}
关于ios - 无法以编程方式同时满足约束条件。 swift iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51901196/