此动画在于运用 CAKeyframeAnimation 关键帧动画,以及贝塞尔关键帧动画
- (void)throwObject:(UIView *)obj fromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint height:(CGFloat)height duration:(CGFloat)duration {
self.showingView = obj;
// 初始化抛物线 path
CGMutablePathRef path = CGPathCreateMutable();
CGFloat cpx = (startPoint.x + endPoint.x)/2;
CGFloat cpy = -height;
CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
CGPathAddQuadCurveToPoint(path, NULL, cpx, cpy, endPoint.x, endPoint.y);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
CFRelease(path);
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.autoreverses = YES;
scaleAnimation.toValue = [NSNumber numberWithFloat:(CGFloat)((arc4random()%4) + 4)/10.0];
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
groupAnimation.delegate = self;
groupAnimation.repeatCount = 1;
groupAnimation.duration = duration;
groupAnimation.removedOnCompletion = NO;
groupAnimation.animations = @[scaleAnimation,animation];
[obj.layer addAnimation:groupAnimation forKey:@"position scale"];
}
代码地址:抛物线动画