Wooly
Wooly

Reputation: 343

How to disable just vertical scrolling in a UIScrollView?

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

Is that possible? Thanks.

Upvotes: 12

Views: 13929

Answers (2)

Ashley Mills
Ashley Mills

Reputation: 53231

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)

Upvotes: 27

user3693546
user3693546

Reputation:

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

}

you must have confirmed to UIScrollViewDelegate

aScrollView.delegate = self;

Upvotes: 2

Related Questions