Smooth shape shift animation

后端 未结 1 323
暗喜
暗喜 2020-12-18 05:31

How to shift shape (from oval to rect and vice versa) animated?

Dirty code:

UIBezierPath *roundedRectBezierPath = [UIBezierPath bezierPathWithRounded         


        
相关标签:
1条回答
  • 2020-12-18 06:11

    If you look at the documentation this is exactly the behavior that you should expect. From the docs:

    If the two paths have a different number of control points or segments the results are undefined.

    You can get around this in two ways: either

    • create the paths yourself in a way that you can guarantee that they both have the same number of paths
    • create a custom animation for the path transition yourself.

    Create paths with same number of segments and control points

    For the first option I would use addArcWithCenter:radius:startAngle:endAngle:clockwise: four times to make up the rounded rect. (It will automatically add the straight lines to your path). You can read more about the construction of Bézier paths in "Thinking like Bézier paths" (written by me). There are some interactive elements there that should help you figure out how adding arcs to a path works.      

    Create a custom path animation

    The other option is to create the paths any way you want with different numbers of control points and/or segments and do the animation yourself. This is an excellent explanation of how to do your own path animations with shape layers.

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