2011-01-23 2 views
5

CGPathAddEllipseInRect 다음에 오는 CAKeyframeAnimation을 사용하여 원을 따라 UIView에 애니메이션을 적용하고 있습니다. 그러나보기는 항상 원래 있던 프레임에 관계없이 같은 위치에서 시작하는 것처럼 보입니다. 경로에서보기의 시작 위치를 조정할 수있는 방법이 있습니까?CGAffineTransform에 대한 시작점 설정

감사합니다.

CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
myAnimation.fillMode = kCAFillModeForwards; 
myAnimation.repeatCount = 5; 
myAnimation.calculationMode = kCAAnimationPaced; 
myAnimation.duration = 10.0; 

CGMutablePathRef animationPath = CGPathCreateMutable(); 

CGPathAddEllipseInRect(animationPath, NULL, rect); 

myAnimation.path = animationPath; 
CGPathRelease(animationPath); 

[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"]; 

답변

1

CGPathAddEllipseInRect의 시작점을 설정할 수 없다고 생각합니다. CGPathAddEllipseInRect, 당신은 사용해야합니다 : CGPathAddArc를

사용하는 대신 (적어도 내가 성공하지 못한)! 예 :

CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
myAnimation.fillMode = kCAFillModeForwards; 
myAnimation.repeatCount = 5; 
myAnimation.calculationMode = kCAAnimationPaced; 
myAnimation.duration = 10.0; 

CGMutablePathRef animationPath = CGPathCreateMutable(); 

NSInteger startVal = M_PI/2; 

//seventh value (end point) must be always 2*M_PI bigger for a full circle rotation 
CCGPathAddArc(animationPath, NULL, 100, 100, 100, startVal, startVal + 2*M_PI, NO); 

myAnimation.path = animationPath; 
CGPathRelease(animationPath); 

[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"]; 

아래에서부터 시계 방향으로 전체 원이 회전합니다. 회전 시작 위치를 변경하려면 startVal 값을 변경하십시오. (풀 회전은 2 * M_PI).

0

이전 대답은 정확하고 작동하지만,이 M_PI는 정수로 반올림됩니다

CGFloat startVal = M_PI/2; 

대신 그렇지 않으면

NSInteger startVal = M_PI/2; 

이어야하고 정확한 각도를 달성 할 수 없습니다 . 오후 8시 30 분 P.S. 이전 답변을 언급하는 평판이 낮습니다. 미안합니다.

관련 문제