我有一个函数,它随机生成一些CGPoints,然后我使用这些点创建一个CGPath。我在关键帧动画中使用该路径来使视图在屏幕上移动。
下面是生成该路径的代码:
- (CGMutablePathRef)generatePathFromCoordinates:(NSArray *)coordinates
{
CGMutablePathRef path = CGPathCreateMutable();
CGPoint point = [(NSValue *)[coordinates objectAtIndex:0] CGPointValue];
CGPathMoveToPoint(path, nil, point.x, point.y);
for (int i=1; i < coordinates.count; i++)
{
point = [(NSValue *)[coordinates objectAtIndex:i] CGPointValue];
CGPathAddLineToPoint(path, nil, point.x, point.y);
}
return path;
}
上面的代码很棒,但动画看起来有点奇怪,所以我想在坐标之间添加曲线而不是直线。像下面的图片一样(我知道我的画技太棒了!)。路径“A”是我目前正在做的,路径“B”是我想达到的效果:
[image]
在查看CGPath参考文献中可用的函数后,我可以看到一些可能完成工作的函数,如
CGPathAddArcToPoint CGPathAddCurveToPoint 。我试图使用这些函数,但没有能够获得所需的效果(可能是因为我使用它们不正确)。
你们能否指出我实现漂亮曲线的正确方法?
提前致谢。