我正在旋转CALayer,并在动画完成后尝试将其停在最终位置.
但是在动画完成后,它会重置到其初始位置.
(xcode docs明确表示动画不会更新属性的值.)
任何建议如何实现这一目标.
我试图动画一段圆的外观.为了存档这个我使用CABasicAnimations工作安静.
动画从顶部开始,很好地移动到整个圆圈的三分之一.但是当动画结束时,圆圈会立即被完全绘制.
我怎么能防止这种情况?
这是我的自定义UIView的源代码:
- (void)drawRect:(CGRect)rect
{
int radius = 100;
int strokeWidth = 10;
CGColorRef color = [UIColor redColor].CGColor;
int timeInSeconds = 5;
CGFloat startAngle = 0;
CGFloat endAngle = 0.33;
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;
circle.position = CGPointMake(CGRectGetMidX(self.frame)-radius, CGRectGetMidY(self.frame)-radius);
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = color;
circle.lineWidth = strokeWidth;
[self.layer addSublayer:circle];
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = timeInSeconds;
drawAnimation.repeatCount = 1.0;
drawAnimation.removedOnCompletion = NO;
drawAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
drawAnimation.toValue …Run Code Online (Sandbox Code Playgroud)