Using Uiscrollview in AutoLayout

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.