円弧に沿ってのUIViewをアニメーション2位置に位置1からの画像に示すように、私は円弧に沿ってビューをアニメーション化したい
何実際に起こることビューアニメーションが完全に記述していることです円の代わりに円を描きます。私の質問は以下のとおりです。
- 私はCGPathAddArcToPointCGPathAddArcまたはを使用する必要がありますか。
- CGPathMoveToPointを使用してビューの初期位置を記述する必要がありますか?
コードをステップ実行すると、CGPointsの値は角度と同じようになります。
は、私は次のコードを使用し、その変異体が、まだ私はそれをクラックするために管理していないのです
CGPoint pointOnCircle(CGPoint centre, float radius, float angle)
{
float x = centre.x + radius * cosf(angle);
float y = centre.y + radius * sinf(angle);
return CGPointMake(x, y);
}
円上CGPointsを取得するには、次の機能を使用します。
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = duration;
pathAnimation.repeatCount = 1;
CGPoint viewCenter = dynamicView.objectCenter;
CGMutablePathRef arcPath = CGPathCreateMutable();
// CGPathMoveToPoint(arcPath, NULL, viewCenter.x, viewCenter.y);
//work out the half way point
float halfwayAngle = dynamicView.angle + (0.5f * self.angleIncrement);
float fullwayAngle = dynamicView.angle + self.angleIncrement;
CGPoint halfwayPoint = pointOnCircle(self.center, self.radius, halfwayAngle);
CGPoint fullwayPoint = pointOnCircle(self.center, self.radius, fullwayAngle);
CGPathAddArc(arcPath, NULL, halfwayPoint.x, halfwayPoint.y, self.radius, dynamicView.angle, fullwayAngle, clockwise);
// CGPathAddArcToPoint(arcPath, NULL, viewCenter.x, viewCenter.y, fullwayPoint.x, fullwayPoint.y, self.radius);
pathAnimation.path = arcPath;
CGPathRelease(arcPath);
[dynamicView.layer addAnimation:pathAnimation forKey:@"arc"];
「MoveToPoint」を最初の位置に、次に「AddArcToPoint」を2番目の位置に移動します。 – Kevin