How to disable just vertical scrolling in a UIScro

2020-07-03 08:01发布

问题:

UIScrollView has a property scrollEnabled to disable all scrolling, but I want to disable only the vertical scrolling.

Is that possible? Thanks.

回答1:

If the scrollView's contentSize.height is less than its bounds.size.height it won't scroll vertically.

Try setting:

scrollView.contentSize = (CGSize){<yourContentWidth>, 1.0}


Swift

scrollView.contentSize = CGSize(width: <yourContentWidth>, height: 1.0)



回答2:

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
    [aScrollView setContentOffset: CGPointMake(aScrollView.contentOffset.x,0)];

}

you must have confirmed to UIScrollViewDelegate

aScrollView.delegate = self;