1. Drag 1 Uiscrollview into the Viewcontroller and add a constraint to it
Constrain the upper and lower left edges to align with the superview
2. In ScrollView, drag in 1 uiview to make it orange for the sake of distinction.
3. Adding a constraint to a view
Constrain the upper and lower left edges to align with the superview
After adding these constraints, we found that there was an error, ignoring
4. To add a width constraint to the view, in this case, the effect is that scrollview can be scrolled vertically, not scrolled horizontally,
Therefore, you can constrain the width of the view to be the same as ScrollView
5. Next add a height constraint to the view
To update a frame
Happy to find that the constraint error has disappeared!
To verify that the ScrollView can slide correctly
We add a blue view to the ScrollView, add a width height constraint of 60,500, and then add to the left and top margins of the yellow view (that is, the superview of the Blue view)
At this point, all constraints are added to completion. Content that needs scrolling can be added in yellow view.
Click Run to see the effect
You can see that the ScrollView can slide as expected
Finally, all the constraints see
Uiscrollview Add constraint points:
The constraint relationship between 1.scrollView and ScrollView Superview is used to determine the ScrollView frame
The constraint relationship of "Contentview" (blue view in this example) in 2.scrollView is used to determine the contentinsets of ScrollView
The width and height of the 3.contentView are used to determine the ScrollView contentsize
By understanding these 3 points, you can happily add a constraint to the ScrollView
Add constraint plots and points for Uiscrollview using AutoLayout