从函数返回 CGPoints

发布于 2025-01-06 21:06:43 字数 537 浏览 1 评论 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[];
}

为什么这不起作用?

I have another question about passing CGPoint in junctions:

(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[];
}

Why is this not working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2025-01-13 21:06:43

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

(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 的签名,您会发现这就是他们正在使用的。现在编译器会抛出一个警告,要求返回内存指针...所以我不确定这是否是首选方式,但它回答了您的问题。

Have to return a pointer to where it is stored at in memory

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

If you look at the signature of CFContextAddLines, you'll see that is what they're using. Now the compiler will throw a warning for returning a pointer to memory... so I'm not sure if this is the preferred way but it answers your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文