我有NSLayoutConstraints
使用视觉格式字符串构建的单独数组,我想用于纵向和横向方向。我尝试了两种在两者之间切换的方法:激活/停用它们,以及添加/删除它们。
激活/停用:
portaitConstraints.forEach {
$0.active = false
}
landscapeConstraints.forEach {
$0.active = true
}
添加/删除:
self.view.removeConstraints(portraitConstraints)
self.view.addConstraints(landscapeConstraints)
这两种方法似乎都可以正常工作并按预期运行,但是使用激活/停用方法时出现以下运行时错误:
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.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
这有一个共同的模式吗?如果它的行为符合预期,我可以安全地忽略该错误吗?一种方法与另一种方法相比是否有更多开销?我认为将“活动”属性翻转到我想要激活的属性上而不是重复向视图添加和删除约束更有意义。
或者这只是一种愚蠢的方式来做到这一点,我需要做一些NSLayoutAttributes
直接改变的事情?