当将某个视图旋转到横向时,我得到了这个日志:
无法同时满足约束。以下列表中可能至少有一个约束是您不想要的。试着这样做:(1)看看每一个约束,试着找出你没有想到的;(2) 找到添加了不需要的一个或多个约束的代码并修复它。(注意:如果您看到的是不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性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]>"
)
将尝试通过打破限制进行恢复
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
在UIViewAlertForUnsatisfableConstraints处设置一个符号断点,以便在调试器中捕获它。中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能有所帮助。
我什么都不懂。我添加了符号UIViewAlertForUnsatisfiableConstraints
断点,但内存地址什么也没告诉我。。。我如何才能以更容易理解的方式找到本日志所讨论的约束?
提前感谢
您可以重新排序约束,以便视图以一致的顺序显示。所以,原来:
<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
的实例,它和一个写着"欢迎来到…"的标签之间有82个点。这个标签大于或等于54个点高。那么在它和CCD_ 3之间有30个点。同时,您设置了一个约束,即UIView
和MyApp.LogoHeaderView
之间不应该有距离。冲突在于,一些约束要求MyApp.LogoHeaderView
和UIView
之间至少有82+54+30==166个点,而另一个约束则表示它们之间有0个点。
你的UI中真的有多个地方有MyApp.LogoHeaderView
和一个写着"欢迎来到…"的标签吗?
当您在IB中定义约束时,我认为没有办法获得更多信息。但是问题出在哪里呢?你知道标签和视图。现在,您可以查看此视图的约束。在更糟糕的情况下,删除所有对象并逐个添加,每次添加下一个项目时都运行应用程序。然后你会发现错误。