Move UIView per UIBezierPath [closed]

2019-05-29 07:07发布

问题:

I've a UIBezierPath drawing this

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?

回答1:

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

Edit:

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)