Resize and move a UIView with Core Animation (CAKeyFrameAnimation)

后端 未结 1 1281
北荒
北荒 2020-12-28 23:35

Is this possible? I can change the opacity and position (center) of the layer but whenever I try to change the size or origin, it doesn\'t work.

    CAAnimat         


        
相关标签:
1条回答
  • 2020-12-29 00:13

    You can both change the size and position of a view or layer in an animation, but you'll want to do so as an animation group, not by creating a path from a series of rectangles.

    I provide an example of a grouped animation that moves a view along a path while shrinking it and lowering its opacity in my answer here. This works by using a CAKeyframeAnimation for the curved path that the view follows (only animating its position), and then using a basic animation to adjust the size of the view's bounds. You could also use a CAKeyframeAnimation there, with multiple CGSizes for each size keyframe you wanted, making sure to wrap them in an NSValue before placing them in an NSArray of keyframes.

    To animate two properties at once, I wrap the two animations in a CAAnimationGroup and apply that to the view's layer.

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