问题
AutoLayout is adding a NSAutoresizingMaskLayoutConstraint that causes a conflict, and it's unclear where and how.
The question is: where does the height of 293 come from?
UIView hierarchy:
The AutoLayout log has been numbered. Xcode labels didn't show up in the AutoLayout logs.
Line 1 seems to be the trouble. Based on the constraints, it seems this is Post View Cell
, which is a custom UICollectionViewCell
.
Yet the sizeForItemAt
UICollectionViewDelegate function does not return this value. If you hard code the return value to something like CGSize(width: 300, height: 100)
, 293 still appears in the log.
So where is 293 coming from?
Line 2 is a constraint set in code, and this is the right value. This view should be Attachment View
.
Lines 3 & 4 refer to Post Content View
, which is a UIStackView
.
Line 5 refers to the Text View
.
Line 6 refers to Attachment View
.
Line 7 is the spacing set by the UIStackView
(Post 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:
An NSAutoresizingMaskLayoutConstraint can arise any time you have a view for which translatesAutoresizingMaskIntoConstraints
is true
(which, unfortunately, is the default when you create a view in code). Make sure that that's not the case.
来源:https://stackoverflow.com/questions/53790691/mysterious-value-introduced-by-nsautoresizingmasklayoutconstraint-set-by-autolay