1 -(void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
2
3
4 //创建一个帧动画
5 CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
6
7 //设置属性
8 anim.keyPath = @"position";
9
10 // UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 300, 400)];
11
12 UIBezierPath *path = [UIBezierPath bezierPath];
13
14 [path moveToPoint:CGPointMake(10, 50)];
15
16 [path addLineToPoint:CGPointMake(300, 400)];
17
18
19 anim.path = path.CGPath;
20
21
22 //设置执行的次数
23 anim.repeatCount = MAXFLOAT;
24
25 anim.autoreverses = YES;
26
27 anim.duration = 1;
28
29 //添加动画
30 [self.iconV.layer addAnimation:anim forKey:nil];
31
32
33 }