CAPropertyAnimation additive

再做一些shaking动画时,通常会指定对称的左右几个点,加入都CAKeyframeAnimation.values中。

但是这就需要计算present layer的点,不太方便。

看了下CAPropertyAnimation有个属性是additive,这个属性根据当前的渲染层的值加上value生成新的渲染的值,也就是动画时present layer的值。

Determines if the value specified by the animation is added to the current render tree value to produce the new render tree value.
Availability

下边的代码的动画效果是一样的,对比下values会有个明确的认识:

- (void)change

{

    

    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];

    animation.values = @[@0,@100,@(-100),@100,@0];

    animation.keyTimes = @[@0,@(1/6.),@(3/6.),@(5/6.),@1];

    animation.duration = 2.f;

    animation.additive = YES; //YES把更改的值追加到当前的present层中 keypath+=value NO是把更改的值设置成当前present层的值keypath = value

    [self.ly.layer addAnimation:animation forKey:@"shaking"];

    

    

    CAKeyframeAnimation* animation1 = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];

    animation1.values = @[@(self.ly1.center.x),@(self.ly1.center.x + 100),@(self.ly1.center.x - 100),@(self.ly1.center.x + 100),@(self.ly1.center.x)];

    animation1.keyTimes = @[@0,@(1/6.),@(3/6.),@(5/6.),@1];

    animation1.duration = 2.f;

    animation1.additive = NO; //YES把更改的值追加到当前的model层中 keypath+=value NO是把更改的值设置成当前present层的值keypath = value

    [self.ly1.layer addAnimation:animation1 forKey:@"shaking"];

    

    

    [button animateWithType:arc4random()%3];

    

    

    [self performSelector:@selector(change) withObject:nil afterDelay:3.f];


}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值