Created
December 6, 2012 10:21
-
-
Save lqik2004/4223499 to your computer and use it in GitHub Desktop.
惯性滚动
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (recognizer.state == UIGestureRecognizerStateEnded) { | |
CGPoint velocity = [recognizer velocityInView:self.view]; | |
CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y)); | |
CGFloat slideMult = magnitude / 200; | |
NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult); | |
float slideFactor = 0.1 * slideMult; // Increase for more of a slide | |
CGPoint finalPoint = CGPointMake(recognizer.view.center.x + (velocity.x * slideFactor), | |
recognizer.view.center.y + (velocity.y * slideFactor)); | |
finalPoint.x = MIN(MAX(finalPoint.x, 0), self.view.bounds.size.width); | |
finalPoint.y = MIN(MAX(finalPoint.y, 0), self.view.bounds.size.height); | |
[UIView animateWithDuration:slideFactor*2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ | |
recognizer.view.center = finalPoint; | |
} completion:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment