Scroll view has ambiguous scrollable content height

Here's what I did:


- I added a scroll view to my layout. I anchored the top, left, right and bottom of the scroll view to other elements in the layout, so no issues there.


- I put two subviews into the scroll view. View 1 is anchored to the top, left, and right of the scroll view and has an explicit height. View 2 is anchored to the left and right of the scroll view, to the bottom of View 1, and also has an explicit height.


Interface builder says "Scroll view has ambiguous scrollable content height". I don't understand why the height is ambiguous since the two subviews have explicit heights. What does interface builder expect me to do to resolve this error? There isn't anything in the inspector that lets me explicitly set the contentSize of the scroll view. I could do it programatically, but I'd rather figure out how to eliminate the error.


Thanks.

Try making a constraint from the bottom of View 2 to the scroll view.


Views inside the scroll view behave differently when it comes to "superview" constraints when the superview is a scroll view. Those constraints don't determine the size or position of the subview; rather, they determine the scroll view's content size. You need an unbroken chain from top of scroll view through all your views to the bottom of the scroll view (with everything having an explicit or intrinsic size). For that reason I always make only one child view of the scroll view, constrained top, left, bottom and right to the scroll view. So it's the only one with the weird constraints. Children of that view have constraints that behave normally.

Scroll view has ambiguous scrollable content height
 
 
Q