设置遵循椭圆路径的CAKeyframeAnimation的起始位置

Chr*_*isM 2 cocoa-touch core-animation objective-c uiview cakeyframeanimation

我试图UIView使用CAKeyframeAnimation跟随创建的路径的圆形动画CGPathAddEllipseInRect,我已经设置好了.但是,有没有办法设置动画的开始位置?我的代码是:

//set up animation
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 10.0;
pathAnimation.repeatCount = 1000;
CGMutablePathRef curvedPath = CGPathCreateMutable();

//path as a circle
CGRect bounds = CGRectMake(60,170,200,200);
CGPathAddEllipseInRect(curvedPath, NULL, bounds);

//tell animation to use this path
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

//add subview
circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ball.png"]];    
[testView addSubview:circleView];

//animate
[circleView.layer addAnimation:pathAnimation forKey:@"moveTheSquare"];
Run Code Online (Sandbox Code Playgroud)

rob*_*off 7

CGPathAddArc而不是CGPathAddEllipseInRect.例如:

CGFloat radiansForHour(CGFloat hour)
{
    return 2 * M_PI * (hour - 3) / 12;
}

...
    CGPathAddArc(curvedPath, NULL, 160, 270, 100, radiansForHour(11), radiansForHour(12 + 11), NO);
Run Code Online (Sandbox Code Playgroud)

请注意,如果您希望它移动12小时,则endAngle参数必须比12小时多12小时startAngle.