gpt4 book ai didi

objective-c - CABasicAnimation - 设置起始笔画位置

转载 作者:可可西里 更新时间:2023-11-01 03:38:17 26 4
gpt4 key购买 nike

我正在为基本圆的绘图制作动画。这工作正常,除了动画开始绘制在 3 点钟的位置。有谁知道我怎样才能让它在 12 点开始?

self.circle = [CAShapeLayer layer];
self.circle.fillColor = nil;
self.circle.lineWidth = 7;
self.circle.strokeColor = [UIColor blackColor].CGColor;
self.circle.bounds = CGRectMake(0, 0, 200, 200);
self.circle.path = [UIBezierPath bezierPathWithOvalInRect:self.circle.bounds].CGPath;
[self.view.layer addSublayer:self.circle];

CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 5.0;
drawAnimation.repeatCount = 1.0;
drawAnimation.removedOnCompletion = NO;
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f];
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[self.circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];

最佳答案

您可以使用 bezierPathWithArcCenter 而不是 bezierPathWithOvalInRect,因为这样可以指定开始和结束角度:

CGFloat radius = self.circle.bounds.size.width/2; // Assuming that width == height
self.circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius)
radius:radius
startAngle:(-M_PI/2)
endAngle:(3*M_PI/2)
clockwise:YES].CGPath;

参见 bezierPathWithArcCenter角度含义的文档。

关于objective-c - CABasicAnimation - 设置起始笔画位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com