How to Animate a UIBezierPath

后端 未结 1 705
一生所求
一生所求 2020-11-30 23:06

i would like to animate a UIBezierPath of a rect to a triangle one, not to animate a view on a path but animate the path itself so it morphs from one shape to another. the p

相关标签:
1条回答
  • 2020-11-30 23:35

    I am not an expert on CoreAnimation but you can define a CABasicAnimation as follows

    CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:@"path"];
    morph.duration = 5;
    morph.toValue = (id) [self getTrianglePath];
    [maskLayer addAnimation:morph forKey:nil];
    

    The first line states that you want to define an animation that changes the path property of the layer. The second line states that the animation takes five seconds and the third line gives the final state of the animation. Finally, we add the animation to the layer. The key is a unique identifier for the animation, that is, if you add two animations with the same key only the last one is considered. This key can also be used to override so called implicit animations. There are a couple of properties of a CALayer that are animated by default. More precisely, if you change one of these properties the change will be animated with a duration of 0.25.

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