需要 CGRect & 帮助iOS 开发版 CGPoint

发布于 2024-10-07 08:30:49 字数 574 浏览 0 评论 0原文

嘿,我正在尝试实现双击缩放,并且正在尝试使用 Apple 的 ScrollViewSuite 示例 和几行给了我错误。

第一个是

tapLocation = midpointBetweenPoints(tapLocation, [touch locationInView:touch.view]);

它说赋值中的类型不兼容。除了比较两个 CGPoint 之外,我无法找到有关 midpointBetweenPoints 的太多信息,我相信这就是我要传递的信息。

给出错误的第二部分是

    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:tapPoint];

它给了我无效的初始值设定项。

有谁知道我做错了什么?

Hey, I'm trying to implement double tap zooming and I'm trying to work with code from Apple's ScrollViewSuite example and several of the lines are giving me errors.

The first one is

tapLocation = midpointBetweenPoints(tapLocation, [touch locationInView:touch.view]);

And it says incompatible types in assignment. I haven't been able to find much information about midpointBetweenPoints other than that it compares two CGPoints and I believe that's what I'm passing it.

Second section that gives an error is

    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:tapPoint];

And it gives me invalid initializer.

Does anyone know what I'm doing wrong?

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

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

发布评论

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

评论(1

愁以何悠 2024-10-14 08:30:49

midpointBetweenPoints 和 ZoomRectForScale:withCenter: 都是示例代码的一部分,而不是 iOS 本身的一部分。

midpointBetweenPoints 返回一个 CGPoint (与赋值错误相关),但未在标头中的任何位置声明。您将看到,在使用它的示例 3_Tiling 中,它在 TapDetectingView.m 的第 176 行定义,在第 54 行声明并在第 118 和 139 行使用。我的猜测是,您要么不包括项目中的代码,或者包含定义但省略声明。 Objective-C 是 C 的超集,因此遵循 C 规则。在 C 中,任何无法找到其声明的函数都假定返回“int”。 添加声明:

CGPoint midpointBetweenPoints(CGPoint a, CGPoint b);

很可能您需要在使用之前

某处。据猜测,您对 ZoomRectForScale:withCenter: 的使用可能是类似的问题。如果未找到 Objective-C 方法的声明,则假定它们返回“id”,它是指向通用 Objective-C 对象的指针。 CGRect 是一个 C 结构体,因此将指针强制转换为它是没有意义的。假设您已包含 RootViewController.m 的第 401 行到 416 行的代码,您还需要确保该声明对调用代码可见。在示例代码中,这是通过以下声明在第 80 行实现的:

@interface RootViewController (UtilityMethods)
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center;
@end

在源文件中声明类似的添加是一种近似 Objective-C 中私有方法的方法。如果您希望它是公共的,您可以将其添加到适当的接口声明中。

Both midpointBetweenPoints and zoomRectForScale:withCenter: are part of the example code rather than part of iOS itself.

midpointBetweenPoints returns a CGPoint (relevant to the error about assignment), but is not declared in a header anywhere. You'll see that in the sample in which it is used, 3_Tiling, it is defined at line 176 of TapDetectingView.m, declared at line 54 and used at 118 and 139. My guess would be that you're either not including the code in your project at all, or are including the definition but omitting the declaration. Objective-C is a superset of C, so follows the C rules. In C, any function for which the declaration cannot be found is assumed to return 'int'. Quite probably you need to add the declaration:

CGPoint midpointBetweenPoints(CGPoint a, CGPoint b);

Somewhere before your use.

At a guess, your use of zoomRectForScale:withCenter: is likely to be a similar issue. If declarations aren't found for Objective-C methods then they're assumed to return 'id', which is a pointer to a generic Objective-C object. CGRect is a C struct, so casting a pointer to it makes no sense. Assuming you've included the code from lines 401 to 416 of RootViewController.m, you also need to ensure the declaration is visible to the calling code. In the sample code, this is achieved on line 80 with the declaration:

@interface RootViewController (UtilityMethods)
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center;
@end

Declaring additions like that inside a source file is a way of approximating private methods in Objective-C. If you want it to be public, you can just add it to the interface declaration proper.

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