如何找出不必要的约束constraints in following list is one you don't want

alone23
  • 253

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:0x166eb400 V:[UIView:0x166ea400(37)]>",
"<NSLayoutConstraint:0x16524b60 UIView:0x166ea400.height == 0.0894*UIView:0x16526700.width>",
"<NSAutoresizingMaskLayoutConstraint:0x1a3b68f0 h=-&- v=-&- UIView:0x16526700.width == UIView:0x1656da10.width>",
"<NSAutoresizingMaskLayoutConstraint:0x1a3b6f30 h=--& v=--& H:[UIView:0x1656da10(320)]>"

)

回复
阅读 8.5k
2 个回答
✓ 已被采纳

严格讲,上述提示并不是出错的约束,而是多余的约束,比如设置了上、下边距,同时又pin了高度,就会导致出现这样的问题。感觉你的问题应该是设置了UIView:0x166ea400高度为37,然后又设置它等于另一个UIView:0x16526700宽度的0.0894。这样就冗余了。
而排查的方法是,在storyboard中挨个找UIView,37是个很好的切入点,我是这样做的,很笨

说你设置了一个View的高度等于另外一个view1的宽度,view1的宽度又等于view2的宽度,然后view2的宽度不是确定值,会引起冲突,这种应该是设置约束优先级的问题?

宣传栏