Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 CGPath在点之间添加曲线_Objective C_Core Graphics_Curve_Cgpoint_Cgpath - Fatal编程技术网

Objective c CGPath在点之间添加曲线

Objective c CGPath在点之间添加曲线,objective-c,core-graphics,curve,cgpoint,cgpath,Objective C,Core Graphics,Curve,Cgpoint,Cgpath,我有一个函数,它随机生成一些CG点,然后从这些点创建一个CGPath。我在关键帧动画中使用此路径来设置屏幕周围视图的动画 使用以下代码生成路径: - (CGMutablePathRef)generatePathFromCoordinates:(NSArray *)coordinates { CGMutablePathRef path = CGPathCreateMutable(); CGPoint point = [(NSValue *)[coordinates objectAt

我有一个函数,它随机生成一些CG点,然后从这些点创建一个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;   
}
-(CGMutablePathRef)generatePathFromCoordinates:(NSArray*)坐标
{
CGMutablePathRef path=CGPathCreateMutable();
CGPoint point=[(NSValue*)[coordinates objectAtIndex:0]CGPointValue];
CGPathMoveToPoint(路径,零,点x,点y);
对于(int i=1;i
上面的代码非常好,但是动画看起来有点奇怪,所以我想在坐标之间添加一条曲线,而不是一条直线。如下图所示(我知道惊人的绘画技巧!)。路径“A”是我目前正在做的,路径“B”是我的目标:

在查看了CGPath参考中可用的函数之后,我可以看到一些可能完成任务的函数,
CGPathAddArcToPoint
CGPathAddCurveToPoint
。我曾尝试过使用这些函数,但未能达到预期效果(可能是因为我使用得不正确)

你们能给我指一个正确的方向来实现一个漂亮的曲线吗

提前感谢

CGPathAddCurveToPoint向贝塞尔路径添加一条三次曲线。在您不知道的情况下,曲线的形状由两个控制点决定(使用曲线的三级方程式)。如果希望曲线具有特定形状,则需要计算两个中间点(偏置于路径当前点的值)和曲线端点。相反,如果您不关心具有特定形状的曲线,您可以选择一些随机点。这是一个实现示例:

for (int i=1; i < coordinates.count; i++)
{
    point = [[coordinates objectAtIndex:i] CGPointValue];
    CGPathAddCurveToPoint(path, 0, randomX(), randomY(), randomX(), randomY(), point.x, point.y);
}
for(int i=1;i

我知道您使用的是CGPath,但是如果您觉得更容易使用,也可以使用OOP with而不是CGPath。

旁注:您可以直接调用[[coordinates objectAtIndex:I]CGPointValue];,你不需要类型转换。谢谢你的回答,我想这应该是其中的一个功能