【发布时间】:2014-01-28 17:55:55
【问题描述】:
我正在尝试为我使用 Paintcode(很棒的应用程序,顺便说一句)制作的贝塞尔曲线制作动画,并在“drawRect”方法中绘制自定义 UIView。
绘图工作正常,但我想为贝塞尔曲线中的单个点设置动画。
这是我的非工作方法:
-(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。
我错过了什么吗? (目标是做一种类似蜡烛的动画)
【问题讨论】:
标签: ios animation uibezierpath paintcode