How can I use Autolayout to set constraints on my UIScrollview?

后端 未结 18 1708
别那么骄傲
别那么骄傲 2020-11-28 00:43

I have spent two days trying out the various solutions for Mixed and Pure Autolayout approaches to achieve what was a trivial scrollview setup prior to autolayout, and it\'s

18条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 01:45

    You should organize your layout like this
    ViewControllerView contains ScrollView, ScrollView contains ContainerView, ContainerView contains 2 Labels

    Then follow 3 steps for make your ScrollView can scroll

    1. Setting ScrollView pin (top/right/bottom/left) to ViewControllerView
      • Setting ContainerView pin (top/right/bottom/left) to ScrollView
      • Set Horizontally in Container (don't set Vertically in Container)
      • Label1 pin (top/right/left) to ContainerView
      • Label1 pin (right/left/bottom) to ContainerView and top to Label1

    HERE is the demo project

    Hope this help

提交回复
热议问题