How do you use auto layout in a scroll view?

后端 未结 3 1504
情话喂你
情话喂你 2020-12-12 05:41

So I\'m using a UIScrollView in a view controller in the latest Xcode. I have buttons inside the scroll view. When I run the application, the scroll view disapp

3条回答
  •  独厮守ぢ
    2020-12-12 06:07

    Hope this will help others as well

    1. When you working scrollView with autoLayout, the view hierarchy should be like

    enter image description here

    A view(View1) which contain the scrollView and a view(View2) which contain inside the scrollView.

    Now put the Constraint for View1

    enter image description here

    yes, pinned it from all the side.

    Do the same step for scrollView as well as View2 , Now it will be giving warning like scrollable content size Ambiguity

    Now,the most important step is to press CTRL and drag from the View2 to View1 , scroll down the popover and select equal width

    enter image description here

    Now it will give you the warning for ambitious scrollView height but when you give proper constraints to the inner element(inside the View1 ) it will also go away.

提交回复
热议问题