gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 06:23:37 26 4
gpt4 key购买 nike

我遇到了一些无法解决的约束问题。如果我能更好地理解控制台窗口中的错误消息(特别是与 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 = NO。//对象mainView.translatesAutoresizingMaskIntoConstraints = false。// swift

它会起作用的!

谢谢

关于ios - NSLayoutConstraint "Unable to simultaneously satisfy constraints"错误以及如何解释它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28672326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com