沿绘制路径动画对象?

eve*_*odd 1 iphone animation objective-c

我最近从apple下载了示例应用程序GLPaint.这个应用程序向我展示了如何实现绘图,但现在我想在绘制的线条上设置图像动画.与应用程序"飞行控制"的工作方式类似,我希望能够为图像绘制路径,然后让图像在此路径上生成动画.

有任何想法吗?

Ato*_*iot 5

你可以创造你的道路

CGMutablePathRef thePath = CGPathCreateMutable();
Run Code Online (Sandbox Code Playgroud)

然后在touchesBegan和touchesMoved添加到您的路径

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  UITouch *touch = [touches anyObject];
  if(touch){
    CGPoint tapPoint = [touch locationInView: self.view];
    CGPathMoveToPoint(thePath, NULL,tapPoint.x,tapPoint.y);    
  }
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
  UITouch *touch = [touches anyObject];
  if(touch){
    CGPoint tapPoint = [touch locationInView: self.view];
    CGPathAddLineToPoint(thePath, NULL,tapPoint.x,tapPoint.y);
  }
}
Run Code Online (Sandbox Code Playgroud)

并且在touchEnded上,正如Joshua所说,创建一个CAKeyframeAnimation并设置其路径到thePath并设置动画的其他属性(持续时间等)并将其应用于您的对象