Ios 设置CAShapeLayer动画以绘制进度圈

Ios 设置CAShapeLayer动画以绘制进度圈,ios,objective-c,core-animation,uibezierpath,cashapelayer,Ios,Objective C,Core Animation,Uibezierpath,Cashapelayer,我试图画一个圆圈,用来表示进展。进度更新可能会很快出现,我想为圆圈的更改设置动画 我试过用下面的方法来做这件事,但似乎没有任何效果。这可能吗 - (id)initWithFrame:(CGRect)frame strokeWidth:(CGFloat)strokeWidth insets:(UIEdgeInsets)insets { if (self = [super initWithFrame:frame]) { self.strokeWidth = stro

我试图画一个圆圈,用来表示进展。进度更新可能会很快出现,我想为圆圈的更改设置动画

我试过用下面的方法来做这件事,但似乎没有任何效果。这可能吗

- (id)initWithFrame:(CGRect)frame strokeWidth:(CGFloat)strokeWidth insets:(UIEdgeInsets)insets
{
    if (self = [super initWithFrame:frame])
    {

        self.strokeWidth = strokeWidth;

        CGPoint arcCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
        CGFloat radius = CGRectGetMidX(self.bounds) - insets.top - insets.bottom;

        self.circlePath = [UIBezierPath bezierPathWithArcCenter:arcCenter
                                                         radius:radius
                                                     startAngle:M_PI
                                                       endAngle:-M_PI
                                                      clockwise:YES];
        [self addLayer];
    }
    return self;
}


- (void)setProgress:(double)progress {
    _progress = progress;
    [self updateAnimations];
}

- (void)addLayer {

    CAShapeLayer *progressLayer = [CAShapeLayer layer];
    progressLayer.path = self.circlePath.CGPath;
    progressLayer.strokeColor = [[UIColor whiteColor] CGColor];
    progressLayer.fillColor = [[UIColor clearColor] CGColor];
    progressLayer.lineWidth = self.strokeWidth;
    progressLayer.strokeStart = 10.0f;
    progressLayer.strokeEnd = 40.0f;

    [self.layer addSublayer:progressLayer];
    self.currentProgressLayer = progressLayer;

}

- (void)updateAnimations{

    self.currentProgressLayer.strokeEnd = self.progress;
    [self.currentProgressLayer didChangeValueForKey:@"endValue"];
}
目前,此代码甚至没有绘制圆,但删除progressLayer的
strokeStart
strokeEnd
将绘制完整的圆


如何让它从某个点开始,并根据我设置的
progress
属性开始绘制圆?

我找到了答案。
strokeStart
strokeEnd
的值是从0.0到1.0,所以我给它的值太高了

因此,我刚刚将设置更新为:

- (void)setProgress:(double)progress {
    _progress = progress * 0.00460;
    [self updateAnimations];
}

我的回答带有例子。通常,您应该将动画添加到CAShapeLayer

我不想使用第三方代码。我想知道自己怎么做。“我不想使用第三方代码。我想知道自己怎么做。”+1。我也有同感。