我想要沿bezierPath逆时针方向设置动画。
目前,下面的代码只允许我按顺时针方向操作。
let arrowHead = UIImageView()
arrowHead.image = UIImage(named: "arrowHead.png")
arrowHead.frame = CGRect(x: 55, y: 300, width: 12, height: 12)
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(50, 240, 320, 240))
let ovalShapeLayer = CAShapeLayer()
ovalShapeLayer.fillColor = UIColor.clearColor().CGColor
ovalShapeLayer.strokeColor = UIColor.lightGrayColor().CGColor
ovalShapeLayer.lineWidth = 1.5
ovalShapeLayer.path = ovalPath.CGPath
self.view.layer.addSublayer(ovalShapeLayer)
let myKeyFrameAnimation = CAKeyframeAnimation(keyPath: "position")
myKeyFrameAnimation.path = ovalPath.CGPath
myKeyFrameAnimation.rotationMode = kCAAnimationRotateAuto
myKeyFrameAnimation.repeatCount = Float.infinity
myKeyFrameAnimation.duration = 6.0
// add the animation
arrowHead.layer.addAnimation(myKeyFrameAnimation, forKey: "animate position along path")
self.view.addSubview(arrowHead)有什么想法吗?
发布于 2016-07-03 15:04:47
好的,明白了。
myKeyFrameAnimation.speed = -1
非常简单..。
发布于 2016-07-03 15:29:38
另一种解决方案是使用bezierPathWithArcCenter...作为文档记录的here,它允许您指定圆的方向。使用-M_PI_2作为起点角度,3 * M_PI_2作为终点角度,将在顶部产生一个圆的起点和终点。
https://stackoverflow.com/questions/38164836
复制相似问题