如何解决如何使时钟指针旋转动画?
我想让圆圈中的一条线围绕中心点旋转动画。像时钟指针一样的东西。 从图像 A 中的位置到图像 B 中的位置
向左一次和向右一次,每个都由击键触发。我的尝试似乎不是正确的解决方案。指针移动到正确的位置,但并没有停在那里,而是回到了起始位置。
CAShapeLayer *circle1 = [CAShapeLayer layer];
[circle1 setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(300,400,100,100)] CGPath]];
[circle1 setStrokeColor:[[UIColor redColor] CGColor]];
[circle1 setFillColor:[[UIColor clearColor] CGColor]];
CAShapeLayer *line1 = [CAShapeLayer layer];
UIBezierPath *line1Path = [UIBezierPath bezierPath];
[line1Path moveToPoint: CGPointMake(350,450)];
[line1Path addLineToPoint:CGPointMake(350,500)];
line1.path = line1Path.CGPath;
line1.fillColor = nil;
line1.opacity = 1.0;
line1.lineWidth = 5;
line1.strokeColor = [UIColor blackColor].CGColor;
[circle1 addSublayer:line1];
[[self.view layer] addSublayer:circle1];
UIBezierPath *endPath = [UIBezierPath bezierPath];
[endPath moveToPoint: CGPointMake(350,450)];
[endPath addLineToPoint:CGPointMake(300,450)];
CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.toValue = (__bridge id _Nullable)(endPath.CGPath);
pathAnimation.duration = 1.0;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[line1 addAnimation:pathAnimation forKey:pathAnimation.keyPath];
有人知道如何正确执行此操作吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。