CABasicAnimation - 设置起始行程位置 [英] CABasicAnimation - Setting start stroke position

查看:162
本文介绍了CABasicAnimation - 设置起始行程位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制一个基本圆圈的动画。这很好用,除了动画开始在3点位置绘制。有谁知道我怎么能在12点开始?

I'm animating the drawing of a basic circle. This works fine, except the animation begins drawing at the 3 o'clock position. Does anyone know how I can make it start at 12 o'clock?

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 ,因为它允许指定开始和结束角度:

You can use bezierPathWithArcCenter instead of bezierPathWithOvalInRect, because that allows to specify a start and end angle:

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 文档,了解角度的​​含义。

See the bezierPathWithArcCenter documentation for the meaning of the angles.

这篇关于CABasicAnimation - 设置起始行程位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆