删除动画

UIBezierPath *movePath = [UIBezierPath bezierPath];

CGPoint fromPoint = CGPointMake(160, 110);
CGPoint toPoint = CGPointMake(280, 460);

[movePath moveToPoint:fromPoint];

[movePath addQuadCurveToPoint:toPoint
                 controlPoint:CGPointMake(toPoint.x, fromPoint.y)];

CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;

CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = YES;

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
opacityAnim.removedOnCompletion = YES;

CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim,opacityAnim, nil];
animGroup.duration = 1;
[imageView.layer addAnimation:animGroup forKey:nil];
 

UIBezierPath是用来创建各种曲线的类,这个类很强大,各种你能想到的都可以用它来完成。

这里我们建立的二次曲线实际上就是从照片的中心点位置到垃圾箱终点的一条曲线。

至于函数中controlPoint的选取,自己查阅API吧,这里就不多说了。

接着我们建立了一个CAKeyframeAnimation的动画,这个主要用于实现动画的轨迹变化,我们将动画的path值设为之前定义的曲线值,这样动画就会按我们设定的轨迹移动了。

接下来是大小变化的动画,设定了最初和最终的画面大小。CATransform3DMakeScale用于生成变换矩阵,紧接着是生成透明度的动画。

由于我们用到了三种动画,所以需要用CAAnimationGroup来一次性的使用它们。

这样我们就完成了这样的动画,试试吧。

猜你喜欢

转载自eric-gao.iteye.com/blog/1714753