画圆圈动画出现先慢后快的情况

    UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 300, 300)];
    [self.view addSubview:demoView];

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.frame = demoView.bounds;

    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.lineWidth = 2.0f;
    [demoView.layer addSublayer:shapeLayer];
    shapeLayer.strokeColor = [UIColor redColor].CGColor;

    UIBezierPath* ratePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(demoView.frame.size.width/2.0, demoView.frame.size.height/2.0) radius:demoView.frame.size.width/2.0 startAngle:(M_PI) endAngle:M_PI*(0.4+1) clockwise:true];
    shapeLayer.path = ratePath.CGPath;

    CABasicAnimation *pathAnima = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnima.duration = 3.0f;
    pathAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pathAnima.fromValue = [NSNumber numberWithFloat:0.0f];
    pathAnima.toValue = [NSNumber numberWithFloat:1.0f];
    pathAnima.fillMode = kCAFillModeForwards;
    pathAnima.removedOnCompletion = NO;
    [shapeLayer addAnimation:pathAnima forKey:@"strokeEndAnimation"];

注意如果不添加此句 会导致动画执行不均匀,出现先慢后快的情况

pathAnima.removedOnCompletion = NO;

你可能感兴趣的:(画圆圈动画出现先慢后快的情况)