Animation of stroke of circle segment ends in complete stroke

后端 未结 1 1811
鱼传尺愫
鱼传尺愫 2020-12-05 09:16

I\'m trying to animate the appearance of a segment of a circle. To archive this I use a CABasicAnimations which works quiet fine.

The animation starts on top and mov

相关标签:
1条回答
  • 2020-12-05 09:29

    When you apply an animation to a layer, Core Animation creates a copy of the layer and animates the properties of the copy. The original layer is called the model layer and the copy is called the presentation layer. An animation never changes the properties of the model layer.

    You tried to fix this by setting removedOnCompletion to NO. You would also have to set the fillMode of the animation to make this work, but it's not really the correct way to animate a property.

    The correct way is to change the property on your model layer, then apply the animation.

    // Change the model layer's property first.
    circle.strokeEnd = endAngle;
    
    // Then apply the animation.
    CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = timeInSeconds;
    drawAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
    drawAnimation.toValue   = [NSNumber numberWithFloat:endAngle];
    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
    

    This is explained in the Core Animation Essentials video from WWDC 2011. I highly recommend watching it.

    0 讨论(0)
提交回复
热议问题