Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 沿绘制的路径设置对象动画?_Iphone_Objective C_Animation - Fatal编程技术网

Iphone 沿绘制的路径设置对象动画?

Iphone 沿绘制的路径设置对象动画?,iphone,objective-c,animation,Iphone,Objective C,Animation,我最近从苹果下载了示例应用程序GLPaint。这个应用程序向我展示了如何实现绘图,但现在我想在绘制的线条上为图像设置动画。与应用程序“飞行控制”的工作原理类似,我希望能够为图像绘制路径,然后在该路径上设置图像动画 有什么想法吗?看,这允许您设置动画运行的路径(CGPathRef)。看,这允许您设置动画运行的路径(CGPathRef)。您可以创建路径 CGMutablePathRef thePath = CGPathCreateMutable(); 然后在触摸开始和触摸移动添加到您的路径 - (

我最近从苹果下载了示例应用程序GLPaint。这个应用程序向我展示了如何实现绘图,但现在我想在绘制的线条上为图像设置动画。与应用程序“飞行控制”的工作原理类似,我希望能够为图像绘制路径,然后在该路径上设置图像动画


有什么想法吗?

看,这允许您设置动画运行的路径(CGPathRef)。

看,这允许您设置动画运行的路径(CGPathRef)。

您可以创建路径

CGMutablePathRef thePath = CGPathCreateMutable();
然后在触摸开始和触摸移动添加到您的路径

- (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);
  }
}

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

您可以创建路径

CGMutablePathRef thePath = CGPathCreateMutable();
然后在触摸开始和触摸移动添加到您的路径

- (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);
  }
}

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

基于AtomRiot的代码,我在我的博客上创建了一个简单的项目。请看,还发布了一段显示结果的短片

但是,当动画结束时,图像将以某种方式重新定位回(0,0),因此可能需要添加额外的代码以在动画完成后重置图像位置

另外,如果发现动画一开始就无法更改,则必须等待动画结束后才能更改


希望这有帮助

基于AtomRiot的代码,我在博客上创建了一个简单的项目。请看,还发布了一段显示结果的短片

但是,当动画结束时,图像将以某种方式重新定位回(0,0),因此可能需要添加额外的代码以在动画完成后重置图像位置

另外,如果发现动画一开始就无法更改,则必须等待动画结束后才能更改

希望这有帮助