Skip to content

Instantly share code, notes, and snippets.

@dvlprliu
Created March 14, 2014 04:23
Show Gist options
  • Save dvlprliu/9542116 to your computer and use it in GitHub Desktop.
Save dvlprliu/9542116 to your computer and use it in GitHub Desktop.
- (void)animateFromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint duration:(CGFloat)duration {
NSLog(@"------%s-------",__func__);
CGFloat r = sqrtf(powf(startPoint.x - endPoint.x, 2) + powf(startPoint.y - endPoint.y, 2));
NSLog(@"r = %f",r);
CGFloat SIN = (startPoint.y - endPoint.y) / r;
CGFloat COS = (startPoint.x - endPoint.x) / r;
NSLog(@"-----------------");
NSLog(@"SIN = %f", SIN);
NSLog(@"COS = %f", COS);
CGFloat farRedius = r + 50;
CGFloat nearRedius = r - 30;
NSLog(@"------------------");
NSLog(@"farRedius = %f",farRedius);
NSLog(@"nearRedius = %f", nearRedius);
CGPoint farPoint = CGPointMake(startPoint.x - COS * farRedius, startPoint.y - SIN * farRedius);
CGPoint nearPoint = CGPointMake(startPoint.x - COS * nearRedius, startPoint.y - SIN * nearRedius);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
CGPathAddLineToPoint(path, NULL, farPoint.x, farPoint.y);
CGPathAddLineToPoint(path, NULL, nearPoint.x, nearPoint.y);
CGPathAddLineToPoint(path, NULL, endPoint.x, endPoint.y);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
animation.duration = duration;
animation.delegate = self;
CGPathRelease(path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment