Skip to content

Instantly share code, notes, and snippets.

@rounak
Created May 2, 2014 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rounak/ea9eb450367bd6badf3c to your computer and use it in GitHub Desktop.
Save rounak/ea9eb450367bd6badf3c to your computer and use it in GitHub Desktop.
Portion of the code that does the deceleration
//get velocity from pan gesture
CGPoint velocity = [panGestureRecognizer velocityInView:self];
if (self.bounds.size.width >= self.contentSize.width) {
//make movement zero along x if no horizontal scrolling
velocity.x = 0;
}
if (self.bounds.size.height >= self.contentSize.height) {
//make movement zero along y if no vertical scrolling
velocity.y = 0;
}
//we need the negative velocity of what we get from the pan gesture, so flip the signs
velocity.x = -velocity.x;
velocity.y = -velocity.y;
POPDecayAnimation *decayAnimation = [POPDecayAnimation animationWithPropertyNamed:kPOPViewBounds];
//last two components zero as we do not want to change bound's size
decayAnimation.velocity = [NSValue valueWithCGRect:CGRectMake(velocity.x, velocity.y, 0, 0)];
[self pop_addAnimation:decayAnimation forKey:@"decelerate"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment