您的位置:首页 > 其它

组合动画CAAnimationGroup

2012-08-30 15:58 309 查看
先在自定义的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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  animation