Auto layout UIScrollView with subviews with dynamic heights

后端 未结 6 1175
情书的邮戳
情书的邮戳 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:51

    My variant for scroll view with !Dynamic! height:

    1) Add scroll view to your UIView. Pin all (top, bottom, lead, trail) constraints.

    2) Add UIView to Scroll View. Pin all (top, bottom, lead, trail) constraints. It will be your Content view. You can also rename it.

    3) Control drag from Content view to Scroll view - Equal width

    4) Add content to your UIView. Set needed constraints. And! At the lower item add bottom constraint NOT Greater or equal (>=)(Like most people talks) BUT Equal! Set it to 20 for example.

    In my situation I have UIImageView in content. I have connected it's height to code. And if I change it to like 1000, scroll is visible. And all works.

    Works like a charm for me. Any questions - welcome to comments.

提交回复
热议问题