5

ベジエ曲線のポイントをアニメーション化することは可能ですか? 線から矢印へのスムーズな移行を試みています。

ベジェポイントをアニメート

コードでの行の外観は次のとおりです

//// Color Declarations
UIColor* white = [UIColor colorWithRed: 1 green: 1 blue: 1 alpha: 0.374];

//// Group
{
    //// Bezier Drawing
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint: CGPointMake(30.5, 43.5)];
    [bezierPath addLineToPoint: CGPointMake(30.5, 29.59)];
    [bezierPath addLineToPoint: CGPointMake(30.5, 15.5)];
    bezierPath.lineCapStyle = kCGLineCapRound;

    bezierPath.lineJoinStyle = kCGLineJoinBevel;

    [white setStroke];
    bezierPath.lineWidth = 5.5;
    [bezierPath stroke];
}

...しかし、ポイントを選択してアニメーション化する方法がわかりません。これは可能ですか?

4

2 に答える 2

14

を使用した明示的な CGPath アニメーションCAShapeLayer:

// Create the starting path. Your curved line.
UIBezierPath * startPath; 
// Create the end path. Your straight line.
UIBezierPath * endPath; 

// Create the shape layer to display and animate the line.
CAShapeLayer * myLineShapeLayer = [[CAShapeLayer alloc] init];

CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.fromValue = (__bridge id)[startPath CGPath];
pathAnimation.toValue = (__bridge id)[endPath CGPath];
pathAnimation.duration = 5.0f;
[myLineShapeLayer addAnimation:pathAnimation forKey:@"animationKey"];
于 2013-09-13T19:50:24.070 に答える
0

あなたが何を求めているのかは明らかではありません。コントロール ポイントの 1 つを移動して線の形状を変更するアニメーションを作成しようとしていますか?

パスへの変更をアニメーション化する方法は、CAShapeLayer を作成し、それをビューのレイヤーのサブレイヤーとしてインストールすることです。次に、シェイプ レイヤーに関連付けられたパスを変更すると、システムは暗黙的なアニメーションを使用して変更を行います。

シェイプ レイヤー内のパスには、同じ数/タイプのコントロール ポイントが必要であることに注意してください。そうしないと、アニメーションの結果が「未定義」になります。

于 2013-09-13T19:25:38.780 に答える