创建动画
CAKeyframeAnimation * keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"bounds"];
修改属性
keyFrame.duration = 3;
keyFrame.values = @[[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)], [NSValue valueWithCGRect:CGRectMake(0, 0, 250, 250)] , [NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)]];
keyTimes : 值代表了出现动画的时刻 , 值得范围是[0, 1],
keyTimes 和Value 是一一对应的 数字是百分比 , 数字必须是递增的 , [0 - 0.4] 执行第一帧 [0.4 - 0.8] 第二帧 [0.8 - 1] 执行第三帧
keyFrame.keyTimes = @[@(0.4),@(0.8),@(1)];
添加动画
[self.changeView.layer addAnimation:keyFrame forKey:@"keyFrame"];
CAKeyframeAnimation * keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
keyFrame.duration = 100;
keyFrame.values = @[(id)[UIColor greenColor].CGColor , (id)[UIColor blueColor].CGColor , (id)[UIColor purpleColor].CGColor , (id)[UIColor whiteColor].CGColor];
keyTimes中的第一个值是 0 , 不能被修改
keyFrame.keyTimes = @[@(0.1),@(0.4),@(0.6),@(0.7)];
[self.changeView.layer addAnimation:keyFrame forKey:nil];
原文地址:http://qccccc.blog.51cto.com/6004423/1554475