标签:
1 // 2 // ViewController.m 3 // 07 CAAnimationGroup 4 // 5 // Created by ZhuJiaCong on 16/4/19. 6 // Copyright © 2016年 wxhl. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 13 14 @property (weak, nonatomic) IBOutlet UIView *animationView; 15 16 @end 17 18 @implementation ViewController 19 20 21 22 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 23 24 //旋转动画 25 CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 26 animation1.fromValue = @0; 27 animation1.toValue = @(M_PI_2); 28 29 //设置动画时间 30 animation1.duration = 1; 31 //重复旋转动画 32 animation1.repeatCount = HUGE_VALF; 33 34 35 // [_animationView.layer addAnimation:animation1 forKey:nil]; 36 37 //在使用关键帧动画来改变背景颜色时 38 //1 不能使用UIColor,必须使用CGColor 39 //2 不能将CGColor包装为NSValue 需要使用桥接来转化为id类型 40 NSArray *colors = @[(__bridge id)[UIColor redColor].CGColor, 41 (__bridge id)[UIColor orangeColor].CGColor, 42 (__bridge id)[UIColor yellowColor].CGColor, 43 (__bridge id)[UIColor greenColor].CGColor, 44 (__bridge id)[UIColor cyanColor].CGColor, 45 (__bridge id)[UIColor blueColor].CGColor, 46 (__bridge id)[UIColor purpleColor].CGColor 47 ]; 48 49 CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"]; 50 animation2.values = colors; 51 52 //设置动画时间 53 animation2.duration = 10; 54 //重复旋转动画 55 animation2.repeatCount = HUGE_VALF; 56 57 // [_animationView.layer addAnimation:animation2 forKey:nil]; 58 59 60 //创建动画组 61 CAAnimationGroup *group = [CAAnimationGroup animation]; 62 //将动画加入到动画组中去 63 group.animations = @[animation1, animation2]; 64 65 //设置组动画的持续时间 66 group.duration = 10; 67 68 [_animationView.layer addAnimation:group forKey:nil]; 69 70 } 71 72 73 74 - (void)viewDidLoad { 75 [super viewDidLoad]; 76 77 _animationView.layer.anchorPoint = CGPointMake(0.5, 0.5); 78 79 80 } 81 82 @end
标签:
原文地址:http://www.cnblogs.com/foreveriOS/p/5407164.html