Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Objective c iPhone中的运动路径/运动指南?_Objective C_Iphone_Animation_Bezier - Fatal编程技术网

Objective c iPhone中的运动路径/运动指南?

Objective c iPhone中的运动路径/运动指南?,objective-c,iphone,animation,bezier,Objective C,Iphone,Animation,Bezier,我想要一个图像根据编程代码绘制的路径移动 我以前也问过类似的问题(),但我发现我问错了。图像不需要是UIImageView。此外,上面给出的答案后来被发现只适用于MacOSX,而不适用于iPhone 无论如何,这是我绘制简单路径的代码 CGContextSetRGBStrokeColor(theContext, 1.0, 0.0, 1.0, 1.0); // Draw them with a 2.0 stroke width so they are a bit more visible. CGC

我想要一个图像根据编程代码绘制的路径移动

我以前也问过类似的问题(),但我发现我问错了。图像不需要是UIImageView。此外,上面给出的答案后来被发现只适用于MacOSX,而不适用于iPhone

无论如何,这是我绘制简单路径的代码

CGContextSetRGBStrokeColor(theContext, 1.0, 0.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(theContext, 2.0);

// Draw a bezier curve with end points s,e and control points cp1,cp2
CGPoint s = CGPointMake(30.0, 120.0);
CGPoint e = CGPointMake(300.0, 120.0);
CGPoint cp1 = CGPointMake(120.0, 30.0);
CGPoint cp2 = CGPointMake(210.0, 210.0);

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, s.x, s.y);
CGPathAddCurveToPoint(path, NULL, cp1.x, cp1.y, cp2.x, cp2.y, e.x, e.y);
CGPathAddCurveToPoint(path, NULL, cp2.x, cp1.y, cp1.x, cp2.y, s.x, s.y);
CGPathCloseSubpath(path);

CGContextSetRGBStrokeColor(theContext, 1.0f, 0.0f, 0.0f, 1.0f);
CGContextAddPath(theContext, self.path);
CGContextSetLineWidth(theContext, 1.0);
CGContextStrokePath(theContext);
其中,上下文为CGContextRef。上述代码的结果将绘制旋转90度的“8”形状。但是,如何使一个图像跟随路径

更新#1:很抱歉重复问题,但我想进一步询问如何根据路径进行图像旋转(即头部向量应遵循路径的切线)。有人能提出一些想法吗


更新#2:如何使路径动态变化?

你在另一篇文章中得到的答案适用于你的情况。您必须自己将AppKit翻译成UIKit。

这应该是对该问题的修改,而不是一个全新的问题。无论如何,你得到了一个很好的答案。在这个答案中,没有多少是Mac特有的