由AutoLayout系统设置的NSAutoresizingMaskLayoutConstraint引入的神秘值

时间:2018-12-15 08:15:04

标签: ios autolayout storyboard nslayoutconstraint nsautoresizingmasklayoutconstraint

AutoLayout添加了一个NSAutoresizingMaskLayoutConstraint,它会引起冲突,目前尚不清楚在何处以及如何发生冲突。

问题是:293的高度从哪里来?

UIView层次结构:

enter image description here

自动版式日志已编号。 Xcode标签未显示在AutoLayout日志中。

第1行似乎很麻烦。根据约束,看来这是Post View Cell,这是自定义的UICollectionViewCell

但是sizeForItemAt UICollectionViewDelegate函数没有返回该值。如果您将返回值硬编码为CGSize(width: 300, height: 100)之类的值,则293仍会出现在日志中。

那么293是哪里来的?

第2行是代码中设置的约束,这是正确的值。此视图应为Attachment View

第3行和第4行引用Post Content View,即UIStackView

第5行引用了Text View

第6行引用了Attachment View

第7行是UIStackViewPost Content View)设置的间距。

1. "<NSAutoresizingMaskLayoutConstraint:0x600002a47610 h=--& v=--& UIView:0x7facf0e126b0.height == 293   (active)>",
2. "<NSLayoutConstraint:0x600002a79a40 UIView:0x7facf0e07110.height == 280   (active)>",
3. "<NSLayoutConstraint:0x600002a785a0 V:[UIStackView:0x7facf0e12890]-(10)-|   (active, names: '|':UIView:0x7facf0e126b0 )>",
4. "<NSLayoutConstraint:0x600002a79180 V:|-(10)-[UIStackView:0x7facf0e12890]   (active, names: '|':UIView:0x7facf0e126b0 )>",
5. "<NSLayoutConstraint:0x600002a7cff0 'UISV-canvas-connection' UIStackView:0x7facf0e12890.top == UITextView:0x7facf283a600'hi'.top   (active)>",
6. "<NSLayoutConstraint:0x600002a7cf00 'UISV-canvas-connection' V:[UIView:0x7facf0e07110]-(0)-|   (active, names: '|':UIStackView:0x7facf0e12890 )>",
7. "<NSLayoutConstraint:0x600002a7d270 'UISV-spacing' V:[UITextView:0x7facf283a600'hi']-(5)-[UIView:0x7facf0e07110]   (active)>"


Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002a79a40 UIView:0x7facf0e07110.height == 280   (active)>

1 个答案:

答案 0 :(得分:1)

只要您拥有translatesAutoresizingMaskIntoConstraintstrue的视图(很遗憾,这是在代码中创建视图的默认视图),就会出现NSAutoresizingMaskLayoutConstraint。确保不是这种情况。