CAKeyFrameAnimation关键帧动画

- (IBAction)pressKeyAnimation:(UIButton *)sender {
//    //1.创建动画
//    CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"bounds"];
//    keyFrame.duration = 3;
//
//    //2.修改属性
//    keyFrame.values = @[[NSValue valueWithCGRect:CGRectMake(0, 0, 150, 150)],[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)],[NSValue valueWithCGRect:CGRectMake(0, 0, 250, 250)]];
//    //keyTimes中的值代表出现动画的时刻,值得范围[0 1]里面的值必须是递增的(不然效果很不好)
//    //keyTimes和values是一一对应的
//    keyFrame.keyTimes = @[@(0.4),@(0.7),@(1.0)];
//    //3.添加动画
//    [self.changeView.layer addAnimation:keyFrame forKey:@"haha"];
    
    CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
    keyFrame.duration = 30;
//    self.view.backgroundColor
    keyFrame.values = @[(id)[UIColor redColor].CGColor,(id)[UIColor blackColor].CGColor,(id)[UIColor orangeColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor grayColor].CGColor,(id)[UIColor blueColor].CGColor,(id)[UIColor yellowColor].CGColor];
    //keyTimes 0 1/7 2/7 3/7 4/7 5/7 6/7 1(时间分配)
    //keyTimes第一个值是0不能改变;最后一个为1同理;
    keyFrame.keyTimes = @[@(0.1),@(0.9),@(1.0),@(0.5),@(0.6),@(0.7),@(1.0)];//(手动时间分配)
    [self.changeView.layer addAnimation:keyFrame forKey:@"hha"];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值