Paintcode (素晴らしいアプリ、btw) で作成したベジエ曲線をアニメーション化しようとしており、「drawRect」メソッドでカスタム UIView を描画しています。
描画は正常に機能しますが、ベジエ曲線の 1 つのポイントをアニメーション化したいと考えています。
これが私の非機能的な方法です:
-(void)animateFlame{
NSLog(@"Animating");
// Create the starting path. Your curved line.
//UIBezierPath * startPath;
// Create the end path. Your straight line.
//UIBezierPath * endPath = [self generateFlame];
//[endPath moveToPoint: CGPointMake(167.47, 214)];
int displacementX = (((int)arc4random()%50))-25;
int displacementY = (((int)arc4random()%30))-15;
NSLog(@"%i %i",displacementX,displacementY);
UIBezierPath* theBezierPath = [UIBezierPath bezierPath];
[theBezierPath moveToPoint: CGPointMake(167.47, 214)];
[theBezierPath addCurveToPoint: CGPointMake(181+displacementX, 100+displacementY) controlPoint1: CGPointMake(89.74, 214) controlPoint2: CGPointMake(192.78+displacementX, 76.52+displacementY)];
[theBezierPath addCurveToPoint: CGPointMake(167.47, 214) controlPoint1: CGPointMake(169.22+displacementX, 123.48+displacementY) controlPoint2: CGPointMake(245.2, 214)];
[theBezierPath closePath];
// Create the shape layer to display and animate the line.
CAShapeLayer * myLineShapeLayer = [[CAShapeLayer alloc] init];
CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.fromValue = (__bridge id)[bezierPath CGPath];
pathAnimation.toValue = (__bridge id)[theBezierPath CGPath];
pathAnimation.duration = 0.39f;
[myLineShapeLayer addAnimation:pathAnimation forKey:@"pathAnimation"];
bezierPath = theBezierPath;
}
これを使用すると、画面上で何も動きません。生成されたランダムな変位は良好で、bezierPath 変数はクラス スコープで宣言された UIBezierPath です。
何か不足していますか?(目標は、ろうそくのようなアニメーションを行うことです)