错误的 setStrokeEnd CAShapeLayer

wrong setStrokeEnd CAShapeLayer

我尝试创建一个简单的圆圈进度,proress 工作但值错误,圆圈在 0.8 而不是 1 时完成,半圆在 0.4 时完成,我没有发现错误:

NSLog(_pathLayer) 打印 0.1,0.2,...1.0 似乎没问题。

- (void)drawRect:(CGRect)rect {

    /* Cerchio rosso centrale */
    UIBezierPath *circlePath = [UIBezierPath bezierPath];
    [circlePath addArcWithCenter:CGPointMake(self.frame.size.width/2,self.frame.size.height/2)
                          radius:60
                      startAngle:degreesToRadians(-90)
                        endAngle:degreesToRadians(360)
                       clockwise:YES];

    [self.layer addSublayer:[self disegnaLinea:circlePath
                                        andWidth:_strokeWidth
                                        andColor:_color
                                           toEnd:0]];
}


- (void)setProgress:(double)progress {

    if (progress != _progress)
    {
        _progress = progress;
        [self updateAnimations];


        NSLog(@"_pathLayer: %f",_pathLayer.strokeEnd);
    }


}

- (CAShapeLayer *) disegnaLinea:(UIBezierPath *)path andWidth:(float)width andColor:(UIColor *)color toEnd:(int)end {

    _pathLayer = [CAShapeLayer layer];
    _pathLayer.frame = self.bounds;
    _pathLayer.path = path.CGPath;
    _pathLayer.strokeColor = [color CGColor];
    _pathLayer.fillColor = nil;
    _pathLayer.lineWidth = width;
    [_pathLayer setStrokeStart:0];
    [_pathLayer setStrokeEnd:end];

    return _pathLayer;
}

- (void) updateAnimations {

    [_pathLayer setStrokeEnd:_progress];
    [_pathLayer didChangeValueForKey:@"endValue"];

    [_progressLabel setText:[NSString stringWithFormat:@"%f",_progress]];
}

如果你这样做 (endAngle - startAngle),你将获得 450 度,这基本上意味着你的路径比一个完整的圆圈长。我的猜测是使用 270 作为 endAngle。干杯。