【问题标题】:Unable to simultaniously satisfy constraints - how do i know which ones conflict无法同时满足约束 - 我怎么知道哪些冲突
【发布时间】:2014-10-26 10:24:23
【问题描述】:

我怎么知道哪些约束冲突?

2014-10-26 12:31:55.713 MyApp[17769:2430918] 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:0x79646340 V:[UIImageView:0x796475f0]-(0)-|   (Names: '|':UIView:0x79641bc0 )>",
    "<NSLayoutConstraint:0x796463a0 V:[UILabel:0x79636150'my settings']-(19)-[UIImageView:0x796475f0]>",
    "<NSLayoutConstraint:0x79646430 V:|-(20)-[UILabel:0x79636150'my settings']   (Names: '|':UIView:0x79641bc0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x79640030 h=-&- v=-&- UIView:0x79641bc0.height == _UITableViewHeaderFooterContentView:0x79639c70.height>",
    "<NSLayoutConstraint:0x7963a190 'UIView-Encapsulated-Layout-Height' V:[_UITableViewHeaderFooterContentView:0x79639c70(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x796463a0 V:[UILabel:0x79636150'my settings']-(19)-[UIImageView:0x796475f0]>

【问题讨论】:

  • 看起来错误是告诉您表格页脚视图的高度为 0 像素高,但您的 [UIlabel]-19-[imageView] 与它冲突。
  • 您好,请您添加限制被打破的图像。还有你是如何设置布局约束的。
  • 您好,请问您是如何设置约束的以及表格页脚视图的高度是多少。据说它试图通过破坏 'V:[UILabel:0x79636150'my settings']-(19)-[UIImageView:0x796475f0]>' 来设置视图,因为它没有得到适当的高度。那么请您记下表格页脚视图的高度以及您是如何设置约束的。
  • 页脚的高度是在运行时使用委托方法定义的,它与 xib 文件中给出的高度相匹配

标签: ios nslayoutconstraint ios-autolayout


【解决方案1】:

首先让我说修复这些并不容易。我在 IB 中创建了大多数东西,所以我通常的方法是清除所有约束并重新构建它们。

在您的情况下,您可能有一个更简单的答案。约束之一是&lt;NSAutoresizingMaskLayoutConstraint:0x79640030 …。这让我怀疑视图是动态添加的。找到那个视图。

在调用-addSubview: (see) 之前将translatesAutoresizingMaskIntoConstraints 设置为NO

此时(希望)视图将加载,但您还没有完成。他们动态添加的视图将不受约束。您需要以编程方式添加任何需要的约束see

【讨论】:

  • 我所有的视图都添加到界面构建器中,给定的视图是我在界面构建器中添加的标签。如果我删除并重建约束,其他一些约束会得到投诉:(
  • @LenaBru 如果您的所有视图都添加到 IB 中,那么您应该会在 IB 中收到有关约束问题的警告。
猜你喜欢
  • 1970-01-01
  • 2012-12-28
  • 1970-01-01
  • 2014-10-27
  • 2014-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多