美文网首页
画圆圈动画出现先慢后快的情况

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

作者: 雾霭天涯 | 来源:发表于2019-09-26 16:42 被阅读0次
        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;

    相关文章

      网友评论

          本文标题:画圆圈动画出现先慢后快的情况

          本文链接:https://www.haomeiwen.com/subject/nmkhyctx.html