我收到此错误:
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:0x1600aec0 V:[UIView:0x102021d0]-(0)-| (Names: '|':UIView:0x1600a980 )>",
"<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0] (Names: '|':UIView:0x1600a980 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>",
"<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-| (Names: '|':UIView:0x1600a980 )>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in
<UIKit/UIView.h> may also be helpful.
生成此错误的视图对左/右/上/下有4个约束,我无法删除它们中的任何一个。
我试过了:
[View setTranslatesAutoresizingMaskIntoConstraints:NO];
没有结果。
你知道如何解决这个问题吗?
谢谢!
答案 0 :(得分:4)
问题在于垂直布局。
<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>
自动调整窗口的遮罩。固定边距和尺寸。你无法改变这一点。
<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>
自动屏蔽(固定边距,可调整大小的内容)。可能是你的控制器的视图。高度为480
(设置为等于窗口大小)。没有什么可以解决的。
<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-| (Names: '|':UIView:0x1600a980 )>
<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0] (Names: '|':UIView:0x1600a980 )>
您可以注意到,两个约束都使用相同的视图([UIView:0x102021d0]
)执行某些操作,并且具有与参数(UIView:0x1600a980
)相同的第二个视图。第二个视图是我们控制器的视图。
这两个约束定义了距第二个视图边缘的距离。第一个定义底部(0
)。第二个定义顶部(494
)。如果超级浏览量的大小为480
,则表示[UIView:0x102021d0]
的高度等于-14
,从而触发该异常。
如何解决?好吧,将494
约束更改为正确的值。你可能甚至不想要“顶部”约束,也许你想要一个固定的高度。
问题是怎么出现的?您可能已经为iPhone 5创建了约束,然后您尝试使用iPhone 4运行该应用程序。如果您将xib中的模拟大小更改为iPhone 4,您应该立即看到问题。
答案 1 :(得分:0)
显然,仍有translatesAutoresizingMaskIntoConstraints
设置为YES
的视图,否则您将无法收到该消息。这可能是视图的超级视图,它会给你带来麻烦。确保它也不会将其自动调整遮罩转换为约束。