Move UIView per UIBezierPath [closed]


I've a <strong>UIBezierPath</strong> drawing this

<a href="https://i.stack.imgur.com/HT53Q.png" rel="nofollow"><img alt="" class="b-lazy" data-src="https://i.stack.imgur.com/HT53Q.png" data-original="https://i.stack.imgur.com/HT53Q.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

And I want the red point to move on the blue path infinitely (from right to left, from left to right)

How can I do that?


You can use CAKeyFrameAnimation. Assign your path to the path property of the animation object, then run the animation on the view's layer.


A little snippet as a hint:

let path = ... // the UIBezierPath let animation = CAKeyFrameAnimation() animation.path = path.CGPath animation.calculationMode = kCAAnimationPaced // This give the animation an even pace animation.repeatCount = HUGE // This makes the animation repeat forever viewToAnimation.layer.addAnimation(animation, forKey: nil)