iOS "UITemporaryLayoutHeight" constraint iOS "UITemporaryLayoutHeight" constraint swift swift

iOS "UITemporaryLayoutHeight" constraint


I've noticed this happening to me if I call layoutIfNeeded on a view before its parent has been laid out. I would bet if you removed someView.layoutIfNeeded() you wouldn't see that error anymore. You could probably also get rid of someView.setNeedsLayout() and replace it with someView.updateConstraintsIfNeeded(). systemLayoutSizeFittingSize shouldn't require the views be actually laid out, it just needs the constraints to be configured properly.


This:

It just contains an 80x80 imageView pinned to the top, left and bottom margins

and this

NSLayoutConstraint:0x7ff16b753190 '_UITemporaryLayoutHeight' V:[ProjectName.SomeView:0x7ff16b772210(0)]

is the source of the problem. UIKit is at some point in the load/layout/display process using a height of 0. Since you have constraints to both top and bottom and imageview has its intrinsic content size, you are telling it to fit the image into zero-vertical space.

The usual way to resolve this is to set either top or bottom constraint's priority to anything less than 1000.


I had this warning when the view doesn't have a superview and layoutIfNeeded is called.My solution was to call layoutIfNeeded after the view is added on a superview. I hope this helps:

- (void)didMoveToSuperview {    [super didMoveToSuperview];    [self layoutIfNeeded];}