画像ビューを円の周りに飛ばすキー フレーム アニメーションを作成しようとしています。CGPathAddCurveToPoint
キーフレームポイントを作成するために使用しています。問題は、イメージ ビューが常に最短 (直線) ルートを使用することです。
特定の半径の円パスを構築する何らかの関数が必要です。
助けてくれてありがとう。
画像ビューを円の周りに飛ばすキー フレーム アニメーションを作成しようとしています。CGPathAddCurveToPoint
キーフレームポイントを作成するために使用しています。問題は、イメージ ビューが常に最短 (直線) ルートを使用することです。
特定の半径の円パスを構築する何らかの関数が必要です。
助けてくれてありがとう。
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
CGPathAddQuadCurveToPoint(path, NULL,middlePoint.x, middlePoint.y,endPoint.x,endPoint.y);
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.removedOnCompletion = NO;
pathAnimation.path = path;
[pathAnimation setCalculationMode:kCAAnimationCubic];
[pathAnimation setFillMode:kCAFillModeForwards];
pathAnimation.duration = 2.0;
[viewTobemoved.layer addAnimation:pathAnimation forKey:nil];
このアニメーションは 1 つのベジェ ポイントのみを使用し、始点から終点までソフトな円を作成します。円の半径も定義して曲線を正確に定義したい場合は、次のリンクを参照できます。
http://blog.shoguniphicus.com/2011/05/19/keyframe-animation-ios-cakeyframeanimation-objective-c/
これでうまくいくでしょうか?
CAKeyframeAnimation* circlePathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"center"];
CGMutablePathRef circularPath = CGPathCreateMutable();
CGRect pathRect = ...; // some rect you define. A circle has equal width/height; radius is half the values you specify here
CGPathAddEllipseInRect(circularPath, NULL, pathRect);
spinAnimation.path = circularPath;
CGPathRelease(circularPath);
アニメーションのキーパスは、円形に飛び回らせたい UIView の center プロパティであることがわかります。