0

我还有一个关于通过CGPoint路口的问题:

(CGPoint[]) displayPoints:(CGPoint) startPoint 
                        withEnd:(CGPoint) endPoint
                 withBaseRotate:(Boolean) baseRotate {

// do some stuf with four or six points
// create a array of the points and return - it


    CGPoint ourPoints[] = {
        CGPointMake(point1.x, point1.y),
        CGPointMake(point2.x, point2.y),
        CGPointMake(point3.x, point3.y),
        //... some more points
    } ;

  return ourPoints[];
}

为什么这不起作用?

4

1 回答 1

0

必须返回一个指向它在内存中存储位置的指针

(const CGPoint *) displayPoints:(CGPoint) startPoint 
                  withEnd:(CGPoint) endPoint
           withBaseRotate:(Boolean) baseRotate {

    CGPoint ourPoints[] = {
        CGPointMake(point1.x, point1.y),
        CGPointMake(point2.x, point2.y),
        CGPointMake(point3.x, point3.y),
        //... some more points
    } ;

  return ourPoints;
}

如果您查看 CFContextAddLines 的签名,您会发现这就是他们正在使用的。现在编译器将抛出一个警告以返回指向内存的指针......所以我不确定这是否是首选方式,但它回答了你的问题。

于 2012-07-25T13:53:02.743 回答