我有一个问题(;)),需要您的帮助.
I have a problem ( ;) ) and I need your help.
让我们看一下图像:
1)我有一条路.可以这样说:
1) I have a path. Lets say it's like this:
let bezierPath = UIBezierPath() bezierPath.moveToPoint(CGPointMake(10.5, 47.5)) bezierPath.addCurveToPoint(CGPointMake(45.5, 23.5), controlPoint1: CGPointMake(10.5, 47.5), controlPoint2: CGPointMake(32.5, 23.5)) bezierPath.addCurveToPoint(CGPointMake(84.5, 47.5), controlPoint1: CGPointMake(58.5, 23.5), controlPoint2: CGPointMake(84.5, 47.5)) bezierPath.addLineToPoint(CGPointMake(10.5, 47.5)) bezierPath.closePath() UIColor.redColor().setStroke() bezierPath.lineWidth = 1 bezierPath.stroke()2)我有一个UIImageView.第一个问题是:如何将其放在路径的指定部分(A点)的顶部?
2) I have an UIImageView. First question is: How to put it on the top of specified part of the path (A point) ?
3)第二个问题:如何从A点到B点对其进行动画处理?
3) Second question: How to animate it from point A to B ?
推荐答案使用CAKeyframeAnimation,您可以使用制作的路径创建动画
By using CAKeyframeAnimation, you can create an animation using the path you made
let animation = CAKeyframeAnimation() // Could also be position.x or position.y if you want to animate a separate axis. animation.keyPath = "position" animation.repeatCount = 0 // How many times to repeat the animation animation.duration = 5.0 // Duration of a single repetition animation.path = bezierPath.CGPath然后将其附加到图像的图层上
and then attach it to your image's layer
imageView.layer.addAnimation(animation, forKey: "move image along bezier path")这另一个 stackoverflow问题帮助我形成了这个答案,如果有的话否则,您可以始终参考 docs .
This other stackoverflow question helped me form this answer, and if all else fails, you could always refer to the docs.
更多推荐
沿路径放置对象,然后移动它(包含IMG)
发布评论