View Full Version : Stopping a deceleration (finish effect) at end of Pan Gesture if another Pan G. start

Sep 15, 2012, 12:12 PM
I have an app that uses a Pan Gesture to move an object, but when the object is released (when the user lifts their finger [or in code speak: 'if (recognizer.state == UIGestureRecognizerStateEnded)']) the object decelerates to a stop rather than just stopping. Here's the code I've used for this:
if (recognizer.state == UIGestureRecognizerStateEnded) {

CGPoint velocity = [recognizer velocityInView:recognizer.view];

// Apply damping to get final spot
// Ideally you'll want to scale this by some magnification factor
CGPoint translation = CGPointMake( /*velocity.x / 8*/0., velocity.y / 8.);

// If the user is close to still, animation just looks wanky
if (fabs(translation.x) < 15. && fabs(translation.y) < 15.) {
translation.x = 0;
translation.y = 0;

// Using a consistent duration keeps fast events fast because there is more space to move in the same amount of time.
// Use the ease out option to slow it down more at the end than at the beginning.
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
recognizer.view.transform = CGAffineTransformTranslate(recognizer.view.transform, translation.x, translation.y);

} completion:^(BOOL finished) {

NSLog(@"completed animation, now do whatever");

The problem is that the user can't start a new pan gesture until the animation has finished. And I really don't know how to change that.
So what I want is a way to make it so that the user can make another Pan gesture on the object whilst the deceleration is still happening.

Does anybody have any ideas or pointers to web articles? I have had a pretty thorough look, but no luck so far...


Sep 16, 2012, 04:27 AM
Hi Everybody!

With the help of some guys at Stack Over Flow, and re-reading the documentation, I came up with the solution. See it here: