2013-10-02 6 views
1

vx (수평으로 이동하는 비율) 및 vy (수직으로 이동하는 비율)를 사용하여 화면 주위를 이동하는 NSObject가 있습니다. 나는 같은 NSObject를 다른 객체로 만들었는지 알고 싶습니다. 어떻게하면 원을 중심으로 원을 그리며 이동시킬 수 있습니까? 감사합니다.NSObject의 원 경로 만들기

+0

코드 일부, 시도한 내용 및 오류를 보는 데 도움이됩니다. – picciano

답변

0
//Prepare the animation - we use keyframe animation for animations of this complexity 
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation  animationWithKeyPath:@"position"]; 
//Set some variables on the animation 
pathAnimation.calculationMode = kCAAnimationPaced; 
//We want the animation to persist - not so important in this case - but kept for  clarity 
//If we animated something from left to right - and we wanted it to stay in the new position, 
//then we would need these parameters 
pathAnimation.fillMode = kCAFillModeForwards; 
pathAnimation.removedOnCompletion = NO; 
pathAnimation.duration = 5.0; 

//Lets loop continuously for the demonstration 
pathAnimation.repeatCount = 1; 

//Setup the path for the animation - this is very similar as the code the draw the line 
//instead of drawing to the graphics context, instead we draw lines on a CGPathRef 
//CGPoint endPoint = CGPointMake(310, 450); 
CGMutablePathRef curvedPath = CGPathCreateMutable(); 
CGPathMoveToPoint(curvedPath, NULL, 10, 10); 

//change the rectangle to adjust diameter and position 
    CGRect rectangle = CGRectMake(50,250,220,150); 

CGPathAddEllipseInRect(curvedPath, NULL, rectangle); 



//Now we have the path, we tell the animation we want to use this path - then we release the path 
pathAnimation.path = curvedPath; 
CGPathRelease(curvedPath); 



[myObject.layer addAnimation:pathAnimation forKey:@"moveTheObject"];