Uiscrollview Add constraint points:
The binding relationship between 1.scrollView and its superview is used to determine the ScrollView frame
The constraint relationship of "Contentview" 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
The principle 1:uiscrollview size depends on the subviews
The size of the Uiscrollview (that is, contentsize) is calculated according to the size occupied by the subviews. Of course, if the content of contentsize is not enough to fill the entire uiscrollview, the scrollbar will not appear and Uiscrollview will not scroll.
The principle 2:subviews size cannot depend on Uiscrollview
Very simple, because the principle 1:uiscrollview size depends on subviews. If the size of subviews is again dependent on Uiscrollview, the layout engine becomes chaotic.
To solve this problem, we need to clear the width of the subview, at least not with the uiscrollview size of the unreliable. (can be closed first with ScrollView's parent view)
4. Modify the contentsize in the code
Sometimes contentsize may be dynamic and need to be modified in the code. It is usually setcontentsize in the Viewdidappear method of Viewcontroller (which can be constraint IBOutlet ).
But in my project found a problem, iphone6/iphone5 test is normal, in the iOS6 set invalid, Set when printing contentsize is normal later print contentsize.height actually become 0, finally put Setcontensize in Dispatch_async (Dispatch_get_main_queue (), ^{ }); Resolve the issue
5. How can I not scroll?
Don't worry, it's because Contentview is not big enough for ScrollView. If you have a sliding effect (which is actually a rebound effect) if the contentsize is not large enough, you can use the properties
| BOOL bounces |
Controls whether the control encounters a border bounce |
| BOOL alwaysbouncevertical |
Controls whether the bounding rectangle is bouncing in the vertical direction |
| BOOL Alwaysbouncehorizontal |
Controls whether the bounding rectangle bounces when the horizontal direction is encountered |
Using Uiscrollview in AutoLayout