UIScrollView with Auto Layout Constraints

Create a single Scroll View in the View of the View Controller (the Scroll View cannot be used as View Controller view itself). Inside the Scroll View, create only a single View (hint: rename it to Content View). Inside, add the content that should be scrollable:

For both the Scroll View and the Content View create constraints using Pin that constrain the View in all directions with a distance of 0 without margin:

If the Content View has an intrinsic content size, for example an Image View with an image set, that’s all that is needed to make the content scrollable. Otherwise, the Content View needs its width and height constrained so that the size of the scrollable area can be known:

You can use a Width / Height constraint for the Content View to set an explicit size of the scrollable content:

To make a direction not scrollable, use a Equal Width / Height constraint with the View of the View Controller:

You can also make the Content View match the size of it’s contents by using constraints that leave no other choice than to resize the Content View itself. For example, here a Stack View is clamped in the Content View by a top and bottom constraint so the layout must set the height of the Content View to fulfill all layout constraints: