获取 "Unable to simultaneously satisfy constraints" 时识别约束
Identifying constraints when getting "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:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>",
"<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>",
"<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>",
"<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
而且我什么都不懂。我添加了符号 UIViewAlertForUnsatisfiableConstraints
断点,但内存地址没有告诉我任何信息...我如何以更不稳定的方式找到此日志所讨论的约束?
提前致谢
当您在IB中定义约束时,我认为没有办法获得更多信息。
但问题是什么?你知道标签和视图。现在您可以查看此视图的约束。
在更糟糕的情况下,删除所有对象并一个一个添加它们,并且每次添加下一个项目时 运行 应用程序。然后你会发现错误。
您可以重新排序约束,以便视图以一致的顺序显示。所以,原文:
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>
<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>
<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>
变成:
<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>
<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>
因此,在垂直方向上,您有一个 MyApp.LogoHeaderView
的实例,它与标签 "Welcome to..." 之间有 82 个点。该标签的高度大于或等于 54 磅。然后它和一个UIView
之间有30个点。同时,您设置了一个约束条件,表示 UIView
和您的 MyApp.LogoHeaderView
之间不应有任何距离。冲突是一些约束要求 MyApp.LogoHeaderView
和 UIView
之间至少有 82 + 54 + 30 == 166 个点,而另一个约束说它们之间有 0 个点。
你的 UI 中真的有多个地方有 MyApp.LogoHeaderView
和标签 "Welcome to..." 吗?
我在将某些视图旋转为横向时收到此日志:
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:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>",
"<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>",
"<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>",
"<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
而且我什么都不懂。我添加了符号 UIViewAlertForUnsatisfiableConstraints
断点,但内存地址没有告诉我任何信息...我如何以更不稳定的方式找到此日志所讨论的约束?
提前致谢
当您在IB中定义约束时,我认为没有办法获得更多信息。 但问题是什么?你知道标签和视图。现在您可以查看此视图的约束。 在更糟糕的情况下,删除所有对象并一个一个添加它们,并且每次添加下一个项目时 运行 应用程序。然后你会发现错误。
您可以重新排序约束,以便视图以一致的顺序显示。所以,原文:
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>
<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>
<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>
变成:
<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>
<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>
因此,在垂直方向上,您有一个 MyApp.LogoHeaderView
的实例,它与标签 "Welcome to..." 之间有 82 个点。该标签的高度大于或等于 54 磅。然后它和一个UIView
之间有30个点。同时,您设置了一个约束条件,表示 UIView
和您的 MyApp.LogoHeaderView
之间不应有任何距离。冲突是一些约束要求 MyApp.LogoHeaderView
和 UIView
之间至少有 82 + 54 + 30 == 166 个点,而另一个约束说它们之间有 0 个点。
你的 UI 中真的有多个地方有 MyApp.LogoHeaderView
和标签 "Welcome to..." 吗?