NSLayoutConstraint "Unable to simultaneously satisfy constraints" 错误以及如何解释它们

NSLayoutConstraint "Unable to simultaneously satisfy constraints" Errors and how to Interpret them

我遇到了一些无法解决的约束问题。如果我能更好地理解控制台 window 中的错误消息(特别是与 NSLayoutConstraints 相关的),我想我会发现它真的很有帮助。这是一个例子:

我有这个约束:

NSLayoutConstraint(item: mainView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: 0)

这对我来说很有意义,我想让 mainView 的高度与 self.view 完全相同。然而,这会产生错误:

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) 
(
    "<NSLayoutConstraint:0x7a94fa10 UIView:0x7a9f95c0.height == UIView:0x7a9d1660.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x7a9488a0 h=--& v=--& V:[UIView:0x7a9f95c0(110)]>",
    "<NSLayoutConstraint:0x7a948490 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a9d1660(430)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7a94fa10 UIView:0x7a9f95c0.height == UIView:0x7a9d1660.height>

我已经注释掉了除此之外的所有其他约束,但我仍然遇到此错误。我认为约束与自身冲突是否正确?

任何人都可以指出正确的方向来解决这个问题吗?

最重要的是,如果有人能帮助我理解这些 NSLayoutConstraint 错误消息,那将非常有帮助。

--

请注意我在这里使用 Swift,但我不介意答案是否在 Objective C。

mainView.translatesAutoresizingMaskIntoConstraints = 否。 // 对象 mainView.translatesAutoresizingMaskIntoConstraints = 错误。 // Swift

会成功的!

感谢