我想在屏幕上绘制路径时对其进行动画处理,我认为使用NSBezierPath
和Core Animation是最好的方法,但我不确定如何实现。
基本上,想法是将从点A到点B的路径慢慢地从A到B进行动画处理,直到路径到达B。很棒的教程可以告诉我如何做到这一点。
我想在屏幕上绘制路径时对其进行动画处理,我认为使用NSBezierPath
和Core Animation是最好的方法,但我不确定如何实现。
基本上,想法是将从点A到点B的路径慢慢地从A到B进行动画处理,直到路径到达B。很棒的教程可以告诉我如何做到这一点。
CAShapeLayer *l = [CAShapeLayer layer];
l.frame = self.view.bounds;
l.strokeColor = [UIColor redColor].CGColor;
CGPoint start = CGPointMake(arc4random()%300+10, arc4random()%400+40);
CGPoint end = CGPointMake(arc4random()%300+10, arc4random()%400+40);
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:start];
[path addLineToPoint:end];
l.path = path.CGPath;
[path release];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.duration = 3.0f;
[l addAnimation:animation forKey:@"myStroke"];
[self.view.layer addSublayer:l];