2013-10-02 3 views
1

У меня есть NSObject, который перемещается по экрану с помощью vx (скорость, с которой он перемещается по горизонтали) и vy (скорость, с которой она перемещается по вертикали). Я хочу знать, сделал ли я еще один из тех же NSObject, как я мог заставить его двигаться в идеальном круге (возможность изменять диаметр, направление по кругу и скорость его движения по кругу) ThanksКак создать 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"]; 
Смежные вопросы