iOS ScrollView needs constraint for y position or height

前端 未结 8 1656
栀梦
栀梦 2020-11-30 18:21
-ViewController
--View
---ScrollView (Top,Bottom,Leading,Trailing spaces to superview set to 0)
----ContentView (Top,Bottom,Leading,Trailing spaces to superview set          


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 19:08

    Xcode 11

    I've been following several tutorials on this for a few hours now, and none of them seem to work. It seems that Xcode 11 has some updates that change how the scroll views work with auto layout.

    1. Add a UIScrollView to the view and add top, bottom, leading, and trailing constraints.
    2. Add a UIView to the scroll view. We will call this the content view.
    3. Add top, bottom, leading, and trailing constraints from the content view to the scroll view's Content Layout Guide. Set the constraints to 0.
    4. Add an equal width constraint between the content view and the scroll view's Frame Layout Guide. (Not the scroll view or the main view!)
    5. Temporarily add a height constraint to the content view so that you can add your content. Make sure that all content has top, bottom, leading, and trailing constraints.
    6. Delete the height constraint on the content view.

      I found an excellent tutorial at this link.

提交回复
热议问题