2016-07-02 8 views
1

bezierPath를 따라 반 시계 방향으로 애니메이션을 적용하고 싶습니다.CAKeyframeAnimation 반 시계 방향

아래 코드는 시계 방향으로 만 수행 할 수 있습니다.

 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) 

어떤 아이디어가 있습니까?

답변

0

알겠습니다.

myKeyFrameAnimation.speed = -1

는 다른 솔루션에서

0

당신이 원의 방향을 지정할 수 있습니다 문서화 herebezierPathWithArcCenter...을 사용하는 것입니다 ... 아주 간단했다. 시작 각도로 -M_PI_2을 사용하고 끝 각도로 3 * M_PI_2을 사용하면 상단에서 시작하여 끝나는 원이됩니다.

+0

감사합니다. 계속 움직일 수있는 방법을 알고 있습니까? 순간에는 애니메이션이 무한히 반복되지만, 이전 애니메이션이 끝난 후 새 애니메이션이 다시 시작되는 동안 일시 중지가 짧게 나옵니다. –

+0

위의 경로를 작성한 경우 경로를 닫아야합니다. – jrturton

+0

귀하의 답변이나 "내"처럼 "위"입니까? –