我在自动布局方面遇到了一些问题。一切都显示正确,一切正常,但我在命令行中收到一些警告消息:
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:0xb6a60f0 H:[UIImageView:0xb645e40(75)]>",
"<NSLayoutConstraint:0xb6d0e90 H:[UIView:0xb6c7350(220)]>",
"<NSLayoutConstraint:0xb6aaea0 H:|-(10)-[UIImageView:0xb645e40] (Names: '|':UITableViewCellContentView:0xb6c1590 )>",
"<NSLayoutConstraint:0xb6c85c0 H:[UIView:0xb6c7350]-(7)-| (Names: '|':UITableViewCellContentView:0xb6c1590 )>",
"<NSLayoutConstraint:0xb6d2270 H:[UIImageView:0xb645e40]-(8)-[UIView:0xb6c7350]>",
"<NSAutoresizingMaskLayoutConstraint:0xb6abd20 h=--& v=--& H:[UITableViewCellContentView:0xb6c1590(300)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xb6d0e90 H:[UIView:0xb6c7350(220)]>
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.
这是我的 nib 文件的样子:
如您所见,它是一个 TableViewCell,我正在使用一个带有 TextView(适用于 iOS7)和一个 AttributedTextView(适用于 iOS6)的 View (示例文本)!
有什么问题?
最佳答案
问题是你有冲突的约束...自动布局有时会很痛苦。 当我遇到这种情况时,我通常会清除所有约束,然后通过选择清除所有约束重新开始。
之后您也可以选择“添加缺少的约束”,并希望 XCode 自动知道您想要做什么。实际上 XCode 有 50-50 的机会正确完成。
从你的屏幕截图来看,你的约束似乎太多了,所以另一种选择是尝试一个一个地删除,并捕捉那些“冲突”的约束。
关于ios - 自动布局显示警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21911237/