layer的动画对象CABasicAnimation(以心跳动画示例)

Posted on 2016-07-07 16:05  柠檬片  阅读(119)  评论(0)    收藏  举报
 1 -(void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
 2     
 3     //创建动画对象
 4     CABasicAnimation *anim = [CABasicAnimation animation];
 5     //设置属性
 6     anim.keyPath = @"transform.scale";
 7     //设置属性值.
 8     anim.toValue = @0;
 9     
10     //设置动画的执行次数
11     anim.repeatCount = MAXFLOAT;
12     
13     //设置动画的执行时长
14     anim.duration = 0.5;
15     
16     //自动反转
17     anim.autoreverses = YES;
18     
19     //添加动画
20     [self.imageV.layer addAnimation:anim forKey:nil];
21     
22     
23 }
示例