How do I stop a UIScrollView from bouncing horizontally?

后端 未结 11 1814
名媛妹妹
名媛妹妹 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:23

    That's strange, because whenever I create a scroll view with frame and content size within the bounds of the screen on either dimension, the scroll view does not scroll (or bounce) in that direction.

    // Should scroll vertically but not horizontally
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    scrollView.contentSize = CGSizeMake(320, 1000);
    

    Are you sure the frame fits completely within the screen and contentSize's width is not greater than the scroll view's width?

提交回复
热议问题