初始化
继承CAShapeLayer
self.progressLayer = [CAShapeLayer layer];
self.progressLayer.path = [self drawPathWithArcCenter];
self.progressLayer.fillColor = [UIColor clearColor].CGColor;
self.progressLayer.strokeColor = RGB(247, 77, 211).CGColor;
self.progressLayer.lineWidth = 26;
self.progressLayer.lineCap = kCALineCapRound;
self.progressLayer.lineJoin = kCALineJoinRound;
[self addSublayer:self.progressLayer];
UIBezierPath
- (CGPathRef)drawPathWithArcCenter {
CGFloat position_y = self.frame.size.height/2;
CGFloat position_x = self.frame.size.width/2;
return [UIBezierPath bezierPathWithArcCenter:CGPointMake(position_x, position_y)
radius:position_y
startAngle:(-M_PI/2)
endAngle:(3*M_PI/2)
clockwise:YES].CGPath;
}
启动
- (void)startAnimation {
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 1.0;
pathAnimation.fromValue = @(0);
pathAnimation.toValue = @(self.percent);
pathAnimation.removedOnCompletion = YES;
[self.progressLayer addAnimation:pathAnimation forKey:nil];
}