错误的setStrokeEnd CAShapeLayer

时间:2015-06-17 07:32:15

标签: cashapelayer

我尝试创建一个简单的循环进度,proress工作但是错误的值,cirlce完成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]];
}

1 个答案:

答案 0 :(得分:3)

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