使用storyboard拖拽约束collection view的时候,遇到如下的警告错误:
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:0x15eb2470 H:[UIImageView:0x15eb2690(32)]>",
"<NSLayoutConstraint:0x15eb2b00 H:[UIImageView:0x15eb2a20(20)]>",
"<NSLayoutConstraint:0x15eb3710 UIImageView:0x15eb2690.leading == UIView:0x15eb2310.leadingMargin + 5>",
"<NSLayoutConstraint:0x15eb3800 H:[UIImageView:0x15eb2690]-(5)-[UILabel:0x15eb2740'2016062890']>",
"<NSLayoutConstraint:0x15eb38f0 UIImageView:0x15eb2a20.trailing == UIView:0x15eb2310.trailingMargin + 5>",
"<NSLayoutConstraint:0x15eb3920 H:[UILabel:0x15eb2740'2016062890']-(5)-[UIImageView:0x15eb2a20]>",
"<NSAutoresizingMaskLayoutConstraint:0x15dbd450 h=--& v=--& H:[UIView:0x15eb2310(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x15eb2470 H:[UIImageView:0x15eb2690(32)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
一开始以为是因为,里面的元素约束过多冲突了,发现,约束没有多,正好,最后,根据错误提示:
"<NSLayoutConstraint:0x15eb2470 H:[UIImageView:0x15eb2690(32)]>",
"<NSLayoutConstraint:0x15eb2b00 H:[UIImageView:0x15eb2a20(20)]>",
<pre name="code" class="objc">"<NSAutoresizingMaskLayoutConstraint:0x15dbd450 h=--& v=--& H:[UIView:0x15eb2310(50)]>"
发现,横向两个元素宽度已经超过52,可是很奇怪的是,我并没有设置他们父视图的宽度为50,最后感谢伟大的stackoverflow,找到了解决办法( Auto layout constraints issue on iOS7 in UITableViewCell):
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
一句代码解决。。。。。
题外话:错误信息提示打断点,断点我会打,运行起来也断了,但是怎么去定位这个问题呢?