Uiscrollview using AutoLayout to scroll vertically

Source: Internet
Author: User

Transferred from: http://dadage456.blog.163.com/blog/static/30310744201491141752716

1, create a blank Uiviewcontroller2, add Uiscrollview to the UIView control, and set Uiscrollview constraints for the parent view UIView (Leading/trailling/top/bottom =0)3, the most important comes, add UIView controls to Uiscrollview ... (1) and renamed Contentview .... (Uiscrollview is mainly based on sub-view to achieve AutoLayout height and width of the calculation) (2then set the Contentview for the parent view Uiscrollview constraints1, leading/trailling/top=0 2, bottom =1 3, Equal height/equal width (contentview height and width equal to Uiscrollview)4, set equal height priority is less than the priority of the bottom just set (the bottom is contentview for uiscrollview constraints), here set priority=999.
Need attention First: why bottom=1rather than bottom =0。 In real-world development, if it is 0 and the content in Contentview does not exceed the height of the screen, the Uiscrollview cannot be pulled down.
Second: To achieve the height of the Contentview to the height of the Uiscrollview contentsize, need to contentview sub-views have a clear top and bottom, Used to let AutoLayout calculate the actual height of the Contentview.
Third: Why to set the priority of equal height ... Let's write a formula that's easier to understand because Scrollview.height=Uiview.height again because Contentview.height= Scrollview.height +1so Contentview.height!=Scrollview.height is the inability to achieve the equal height of this constraints. Will error. Just adjust the priority to solve this problem, conflict, priority to adapt to the height of the contentview .... Now you can add the controls you want to add on the Contentview, but remember that if the control you want to add is already beyond the screen, you need to add bottom and top (no more than you can) to the contentview inside the child controls. In this way AutoLayout can calculate the height of the Contentview, and assign this height to the Uiscrollview contentsize, to achieve the adaptive height ... PostScript: Contentview If use Uilabel, to give Uilabel clear height constraint, so that auto layout can calculate the height.

Uiscrollview using AutoLayout to scroll vertically

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.