我有一个 NSObject,它使用 vx(水平移动的速率)和 vy(垂直移动的速率)在屏幕上移动。我想知道我是否制作了另一个相同的 NSObject,如何让它在一个完美的圆圈中移动,(能够改变直径,围绕圆圈的方向以及它围绕圆圈路径移动的速度)谢谢
问问题
618 次
1 回答
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"];
于 2013-10-02T21:26:04.877 回答