In Swift code, how can I start and animate a UIView
so that it moves in a motion along a circular path, then bring it to an end gracefully? Is it possible to achieve this using a CGAffineTransform
animation?
I have prepared a GIF below showing the type of animation I'm trying to achieve.
Updated: Update code to Swift 4. Use
#keyPath
rather than string literal forkeyPath
.Use
UIBezierPath
andCAKeyFrameAnimation
.Here is the code:
Here is the capture:
Moreover, you can set the
anchorPoint
property ofsquareView.layer
to make the view not animate anchored in it's center. The default value ofanchorPoint
is (0.5, 0.5) which means the center point.