2

で作成されたパスをたどるUIViewを使用して、円内のをアニメーション化しようとしています。これはうまく設定しました。しかし、アニメーションの開始位置を設定する方法はありますか? 私のコードは次のとおりです。CAKeyframeAnimationCGPathAddEllipseInRect

//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"];
4

1 に答える 1

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);

12 時間移動する場合は、endAngleパラメータを より 12 時間長くする必要があることに注意してくださいstartAngle

于 2011-10-26T19:53:01.460 に答える