Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a UIScrollView from bouncing horizontally?

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 horizontally, and basically expose blank sections of the UI. I have tried setting:

scrollView.alwaysBounceHorizontal = NO;
scrollView.directionalLockEnabled = YES;

Which helps a little, but still doesn't stop the user from being able to drag horizontally. Surely there is a way to fix this easily?

like image 654
rustyshelf Avatar asked Oct 06 '08 10:10

rustyshelf


People also ask

What is scroll bounce?

The scroll bounce effect, which is also known as 'elastic scrolling', basically refers to a bounce whereby empty space can be seen for a moment when you scroll to the very top or bottom of the page.

What is scroll view in Swift?

The scroll view displays its content within the scrollable content region. As the user performs platform-appropriate scroll gestures, the scroll view adjusts what portion of the underlying content is visible. ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality.


2 Answers

scrollView.bounces = NO;

Worked for me.

like image 174
Asnis Apps Avatar answered Oct 16 '22 08:10

Asnis Apps


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?

like image 20
Mike McMaster Avatar answered Oct 16 '22 09:10

Mike McMaster