views:

318

answers:

4

I'm trying to figure out how to calculate where the scrollview will stop when a user does a swipe gesture and the scrollview goes into deceleration. I'm trying to use the delegate functions, but I can't accurately figure it out. Please help!

- (void) scrollViewDidScroll:(UIScrollView *)scrollView;
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
A: 

Sounds complicated. The user may start scroll again while it is decelerating, stop it suddenly or what not. Maybe you can get by with just doing DidEndDecelerating, i.e just detecting the position when the scrolling is over?

Jaanus
I can't. I have to figure it out when "scrollViewWillBeginDecelerating" is called.
spin-docta
A: 

It should be simple math. The contentOffset property of the scrollview is updated each time scrollViewDidScroll is called. You only need to save the vector between two positions and the time to get at least a descent end-position of the deceleration.

Note that the user can stop the deceleration any time by tapping on the scrollview as Jaanus pointed out.

Jens Utbult
Easier said then done.
spin-docta
+1  A: 

Unfortunately UIScrollView doesn't work this way-- there's no way to ask it up front where the deceleration ends.

quixoto
A: 

There is a variable for the current acceleration that is kept in the UIScrollView implementation but using that as a solution is impossible because you can't compile the code for a device.

spin-docta