CABasicAnimation – 设置开始行程位置
我正在为一个基本的圈子绘制animation。 这工作正常,除了animation开始绘制在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
,因为它允许指定开始和结束angular度:
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;
有关angular度的含义,请参阅bezierPathWithArcCenter文档。
- 在CABasicAnimation中闪烁以进行旋转
- 使用UINavigationController边缘滑动时,CABasicAnimation会重置
- 为什么当我为我的CABasicAnimation设置一个较低的持续时间值时,它会跳转吗?
- 我如何同时animationUIImageView的图像和UIImageView本身?
- UIBezierPath + CAShapeLayer – animation圈起来填满
- animationCALayer背景颜色和更新模型值
- 主页button被按下时,CABasicAnimation消失
- 如何在UIViewanimation过程中animationUIView图层的子图层?
- 圆弧段的笔画animation以完整笔画结束