为Circle Progress Bar创建动画

时间:2017-02-02 00:22:07

标签: ios objective-c

我正在尝试使用UIBezierPath创建一个进度弧,它将在一个完整的圆圈中四处走动并在完成正确的进度后完成动画。所以基本上它需要做到整整360度,然后走得更远,它需要去满足它的进步。截至目前,我只能将它设置为动画,以达到它的结束角度:

CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = 2.0; // "animate over 10 seconds or so.."
    drawAnimation.repeatCount         = 1.0;  // Animate only once..

    // Animate from no part of the stroke being drawn to the entire stroke being drawn
    drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    drawAnimation.toValue   = [NSNumber numberWithFloat:1.0f];

    // Experiment with timing to get the appearence to look the way you want
    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    // Add the animation to the circle
    static dispatch_once_t once;
    dispatch_once(&once, ^ {
        [progressArc addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
    });

如何让我的弧线以这样的方式制作动画,它会一直绕着并以正确的终止角度停止?

1 个答案:

答案 0 :(得分:0)

您可以通过创建CAValueFunction使图层为旋转设置任意量(包括> 360度)。在this thread上查看我的第二个答案。该线程中的代码位于Objective-C中,看起来就像你想要的那样。对于阅读此线程的其他人需要Swift代码,发表评论我会尝试找到创建Swift示例的时间。

相关问题