无法同时满足约束。

时间:2014-12-10 13:59:02

标签: ios objective-c iphone xcode nsautolayout

有人能帮我理解这个Autolayout例外吗?

以下列表中的至少一个约束可能是您不想要的约束。试试这个:  (1)看看每个约束,并试图找出你不期望的; (2)找到添加了不需要的约束或约束的代码并修复它。 (注意:如果您正在查看您不了解的NSAutoresizingMaskLayoutConstraints,请参阅

的文档。
UIView property translatesAutoresizingMaskIntoConstraints) 
(
"<NSLayoutConstraint:0x7f9b3c030f30 H:[UIImageView:0x7f9b3c042530(80)]>",
"<NSLayoutConstraint:0x7f9b3c04c980 UIImageView:0x7f9b3c042530.leading == UIView:0x7f9b39ef83e0.leadingMargin - 8>",
"<NSLayoutConstraint:0x7f9b3c03be80 H:[UIImageView:0x7f9b3c042530]-(8)-[UILabel:0x7f9b3c03c520'Distance']>",
"<NSLayoutConstraint:0x7f9b39ef6d30 H:[UILabel:0x7f9b3c03c520'Distance']-(9)-[UILabel:0x7f9b3c03c330'Hip Hop']>",
"<NSLayoutConstraint:0x7f9b39ecdf60 UILabel:0x7f9b3c03c330'Hip Hop'.width == UILabel:0x7f9b39eef850'Price'.width>",
"<NSLayoutConstraint:0x7f9b39ecdfb0 UILabel:0x7f9b3c03c330'Hip Hop'.width == UILabel:0x7f9b3c03c520'Distance'.width>",
"<NSLayoutConstraint:0x7f9b39eed730 H:[UILabel:0x7f9b3c03c330'Hip Hop']-(9)-[UILabel:0x7f9b39eef850'Price']>",
"<NSLayoutConstraint:0x7f9b39eed780 UIView:0x7f9b39ef83e0.trailingMargin == UILabel:0x7f9b39eef850'Price'.trailing - 3>",
"<NSAutoresizingMaskLayoutConstraint:0x7f9b39edf060 h=--& v=--& H:[UIView:0x7f9b39ef83e0(50)]>"
)

将尝试通过违反约束来恢复

 <NSLayoutConstraint:0x7f9b3c030f30 H:[UIImageView:0x7f9b3c042530(80)]>

帮助感谢。

1 个答案:

答案 0 :(得分:0)

无论您在代码中添加什么视图,都应该添加行...

imageView.translatesAutoresizingMaskIntoConstraints = NO;