When using storyboard and xib, we often use ScrollView, as well as automatic layout autolayout, but ScrollView and AutoLayout are used in a relatively complex sense. According to the practice, I say my understanding, in the storyboard or Xib, ScrollView determines the size of the contentsize based on the size of the view below it.
Take a look at the effect
1. Create a project, drag a scrollview into the storyboard, such as
2. Select ScrollView to add the constraint.
3. Drag a view onto the ScrollView, then add the upper and lower left and right around the constraint.
4. After the addition, may report a mistake, for example, this temporarily do not take care of.
5. Let's make sure that we need to scroll horizontally or vertically, or both horizontally and vertically.
A. Both the horizontal and vertical directions need to be scrolled without adding
B. Horizontal direction scrolling requires the following constraint to be added
C. You need to add the following constraint in the vertical direction
6. Let's take a horizontal scroll for example, we need to determine the width we want and add a fixed width constraint.
7. Select View to update frame
8. If you want to dynamically set the width of the scrollview, that is, set the value of the view's width constraint, we pull it into a property and then modify its value.
9. If the width is determined, it can be modified in-(void) Updateviewconstraints This method, or it can be modified elsewhere.
10. Now running, you can scroll horizontally. The vertical direction of scrolling is similar to the setting for horizontal scrolling. Let's add two views, drag a view (I set it to gray) to the layout, and add constraints, such as
11. Drag and drop a view, set the background color to red, set the frame to what we need, and my side will set X to 600.
12. We add a constraint to the second view, such as
13. We also need to set a constraint, that is, the second view distance Superview distance, is the second view of the leading constraints
14. Then pull the constraint leading property, set his value in-(void) updateviewconstraints
Such as
This will be OK.
Automatic layout needs to be more practical, there are a lot of details to pay attention to.
Demo address for this example: http://download.csdn.net/detail/h1101723183/8253159
Vertical demo in http://download.csdn.net/detail/h1101723183/8266503
AutoLayout of Storyboard Way ScrollView