It took me a while to figure how to get a UIScrollView working with AutoLayout so here are my notes how to do it. This is around the third time I had to do it and can never remember, so noting it down for future reference.
- The UIScrollView has to have only one child UIView (call it
ContentView
) - Put all your views into
ContentView
- Make
ContentView
have an Equal Width constraint with the superview of the UIScrollView - Make sure constraints for the scroll view ensure it has the same width as its superview.
- Make sure
ContentView
is pinned exactly to the scroll view - all the constraints for leading, trailing, top and bottom spacing should be 0. - Use Autolayout for the views in the
ContentView
. You have to make sure that the height is computable, for example by ensuring the very bottom element has a fixed bottom spacing to the superview margin.
Hope that was helpful.