加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – CABasicAnimation – 设置起始行程位置

发布时间:2020-12-16 07:52:41 所属栏目:百科 来源:网络整理
导读:我正在绘制一个基本圆圈的动画.这很好用,除了动画开始在3点位置绘制.有谁知道我怎么能在12点开始? self.circle = [CAShapeLayer layer];self.circle.fillColor = nil;self.circle.lineWidth = 7;self.circle.strokeColor = [UIColor blackColor].CGColor;se
我正在绘制一个基本圆圈的动画.这很好用,除了动画开始在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,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文档.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读