[英]Error: Unable to simultaneously satisfy constraints
我收到此错误:
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];
没有结果。
你知道如何解决这个问题吗?
谢谢!
问题出在垂直布局中。
<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
)。 如果superview的大小为480
,则表示[UIView:0x102021d0]
高度等于-14
,触发该异常。
怎么解决? 好吧,将494
约束更改为正确的值。 有可能你甚至不想要“顶部”约束,也许你想要一个固定的高度。
问题是怎么出现的? 您可能为iPhone 5创建了约束,然后您尝试使用iPhone 4运行应用程序。如果您将xib中的模拟大小更改为iPhone 4,则应立即看到问题。
仍然有一些视图将translatesAutoresizingMaskIntoConstraints
设置为YES
设置为YES
,否则您将无法获得该消息。 这可能是视图的超级视图,它会给你带来麻烦。 确保它也不会将其自动调整掩码转换为约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.