Auto layout UIScrollView with subviews with dynamic heights

后端 未结 6 1164
情书的邮戳
情书的邮戳 2020-11-29 19:28

I\'m having troubles with UIScrollView using auto layout constraints. I have the following view hierarchy, with constraints set through IB:

- ScrollView (lea         


        
6条回答
  •  悲&欢浪女
    2020-11-29 19:50

    I use pure structure like the following

    -view
      -scrollView
        -view A
        -view B
        -Button
    

    Make sure Button(THE LAST view) has a constraint(vertical spacing from its bottom to superview, which is the scrollview), in this case, no matter what changes for your view A and view B would be, scrollView's height will be changed accordingly.

    I reference to this great online book site.

    Just read the "Creating a scroll view" section, you should have an idea.

    I had the similar problem that I was creating a detail view and using Interface Builder with Auto layout is such a good fit for the task!

    Good luck!

    (Additional resources:

    Stack overflow discussion about the auto layout for scroll view.

    iOS 6 has a Release Notes talking about Auto Layout support for UIScrollView.

    Free online iOS book explanation about scroll view. This actually helped me a lot!

提交回复
热议问题