组合动画CAAnimationGroup

先在自定义的ViewController里声明定义一个UIImageView

1 @property (nonatomic,retain) UIImageView *imgView;
1 @synthesize imgView;

在viewDidLoad函数里添加图片,并执行组合动画

复制代码
 1    //添加图片
 2     imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon@2x.png"]];
 3     imgView.frame = CGRectMake(100, 100, imgView.frame.size.width, imgView.frame.size.height);
 4     [self.view addSubview:imgView];
 5     [imgView release];
 6     
 7     //贝塞尔曲线路径
 8     UIBezierPath *movePath = [UIBezierPath bezierPath];
 9     [movePath moveToPoint:CGPointMake(10.0, 10.0)];
10     [movePath addQuadCurveToPoint:CGPointMake(100, 300) controlPoint:CGPointMake(300, 100)];
11     
12     //以下必须导入QuartzCore包
13   //关键帧动画(位置)
14     CAKeyframeAnimation * posAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
15     posAnim.path = movePath.CGPath;
16     posAnim.removedOnCompletion = YES;
17     
18     //缩放动画
19     CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
20     scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
21     scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
22     scaleAnim.removedOnCompletion = YES;
23     
24     //透明动画
25     CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
26     opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
27     opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
28     opacityAnim.removedOnCompletion = YES;
29     
30     //动画组
31     CAAnimationGroup *animGroup = [CAAnimationGroup animation];
32     animGroup.animations = [NSArray arrayWithObjects:posAnim, scaleAnim, opacityAnim, nil];
33     animGroup.duration = 1;
34     
35     [imgView.layer addAnimation:animGroup forKey:nil];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值