Xamarin iOS Autolayout: Resize width and vertical scroll automatically for various devices while keeping the horizontal scroll disabled

前端 未结 4 978
慢半拍i
慢半拍i 2020-12-22 00:21

I want to create a page which has a vertical but no horizontal scroll. It must adjust width of the content and vertical scroll automatically as per screen size.

Som

4条回答
  •  情歌与酒
    2020-12-22 01:14

    As I mentioned here .

    Refer to Step 1 and Step 2 ,set constraints on Scrollview and containerView.

    I remove the margin between Scrollview and View , and I add some controls on the containerView , so it looks like as below:

    Notice

    1. Since we set the containerView's width equal to scrollview's width, the width is fixed, so we can scroll vertically not horizontally.

    2. Height of controls and spaces between them should be set clearly, because the contentSize is auto calculated by adding them. (If contentSize is greater than the height of screen ,the scrollview can be scrolled)

    I saw you set those constrains on controls , but you can't scroll down to see the controls out of screen, I think you are missing to set bottom margin on the last control(the downmost one).

    Let us do a test.

    1. We set the margin (between button and textfield ) to 1000 and don't set bottom margin between the textfield and containerView.

    Result : can't scroll down to see the textfield out of screen.

    2. Set the margin 1000 and add a bottom margin(10) between textfiled and containerView.

    Result: can scroll

    Demo Link

提交回复
热议问题