How do I stop a UIScrollView from bouncing horizontally?

后端 未结 11 2040
名媛妹妹
名媛妹妹 2021-02-05 12:07

I have a UIScrollView that shows vertical data, but where the horizontal component is no wider than the screen of the iPhone. The problem is that the user is still able to drag

11条回答
  •  难免孤独
    2021-02-05 12:25

    Whether or not a view scrolls (and bounces) horizontally depends on three things:

    • The content size
    • The left and right content insets
    • The width of the scroll view -

    If the scroll view can fit the content size plus the insets then it doesn't scroll or bounce.

    Avoid horizontal bouncing like so:

    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width - scrollView.contentInset.left - scrollView.contentInset.right, height);
    

    I am adding this answer because the previous ones did not take contentInset into account.

提交回复
热议问题