Whenever I add a subview to a UIScrollView, I must add 6 constraints instead of 4.
How to reproduce the problem:
- Create a new Single View application.
- In the storyboard, add a UIScrollView which fills up the entire screen.
- Add its missing constraints (this should add 4 constraints to the superview, such as "Top Space to: Superview).
- Add a new UIView as a subview of the UIScrollView. Size it so it is a small rectangle.
- Choose to add the missing constraints on this box.
You will notice that it added 6 constraints:
- 4 for trailing/leading/top/bottom to superview
- 1 for width
- 1 for height
If you try to delete the width or height constraints, all the constraints become orange. The view should be able to determine its width via its trailing and leading constraints. Similarly, the view should be able to determine its height via its top and bottom constraints.
Why are all 6 of these required, then?
Note: If you try this same thing with a UIView instead of a UIScrollView, then everything works as expected.