views:

401

answers:

1

What's the best way to immediately stop the deceleration of an UIScrollView in iPhone 3.0?

I would like to keep the deceleration of the UIScrollView until it naturally stops or the user performs a certain action, whatever happens first.

Thanks!

+1  A: 

Hi

Untested suggestion coming up:)

When the button tap event is caught, you read what the [scrollView contentOffset].x is, and set the offset to this value with animation OFF.

RickiG
It works and seemed a non-hacky way of doing it. However, for some unknown reason it made the scroll indicators flash in the wrong place. The following code stops the deceleration and also avoids the aforementioned visual effect: myScrollView.showsHorizontalScrollIndicator = NO; myScrollView.showsVerticalScrollIndicator = NO; [myScrollView setContentOffset:myScrollView.contentOffset animated:NO]; myScrollView.showsHorizontalScrollIndicator = YES; myScrollView.showsVerticalScrollIndicator = YES;Ugly code.
hgpc
Glad it worked:)Does "scroll indicators flash in the wrong place" mean that the scrollbars were not at the right side and the bottom?I reckon you have [scrollView setPagingEnabled:YES]; and that this maybe could confuse the scrollView a bit. ScrollView :"The settings says scroll to next page and draw the scrollBars at coordinate x and y" You:"Stop what you are doing and figure out for your self where to draw the scrollbars!".I just did something similar where I made a scrollView that snapped to every 80 px, but I used animation:YES and that might give it a bit more time to adjust?
RickiG