我有一个问题(;)),我需要你的帮助.
让我们看看图像:
1)我有一条路.让我们说它是这样的:
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点)的顶部?
3)第二个问题:如何从A点到B点进行动画处理?
最佳答案 通过使用CAKeyframeAnimation,您可以使用您创建的路径创建动画
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
然后将其附加到图像的图层
imageView.layer.addAnimation(animation, forKey: "move image along bezier path")
这个其他stackoverflow question帮助我形成了这个答案,如果一切都失败了,你总是可以参考docs.