关于 MKOverlayView 的困惑

发布于 2024-11-26 08:09:53 字数 589 浏览 2 评论 0原文

我一直在 iPhone 上使用 MapKit 的图层,我遇到的一个库是这个: https://github.com/mtigas/iOS-MapLayerDemo/。这非常有帮助,而且看起来效果很好。然而,我试图了解并理解它是如何工作的,但我遇到了一些麻烦。

在此页面上,例如:https://github。 com/mtigas/iOS-MapLayerDemo/blob/master/MapLayerDemo/Classes/CustomOverlayView.m, 在顶部,定义了 4 个自定义函数。我认为这些功能是添加到 MKOverlayView 的正常功能中的?问题是,我找不到这些新函数实际上是从哪里调用的,因此我在理解这个页面的工作原理时遇到了一些困难。它似乎不是来自项目中的任何其他文件。

我很感激任何帮助,谢谢。

I've been working with layers for MapKit on the iPhone, and one library that I came across was this one: https://github.com/mtigas/iOS-MapLayerDemo/. It's very helpful, and seems to work fine. However, I'm trying to go through and understand a bit how it works, but I'm having some trouble.

On this page, for example: https://github.com/mtigas/iOS-MapLayerDemo/blob/master/MapLayerDemo/Classes/CustomOverlayView.m,
at the top, there are 4 custom functions defined. I assume these functions are adding on to the normal features of MKOverlayView? The thing is, I can't find where any of these new functions are actually called from, and thus I'm having some trouble understanding how this page works. It doesn't seem to be from any of the other files within the project.

I appreciate any help, thanks.

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

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

发布评论

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

评论(1

听风念你 2024-12-03 08:09:53

在评论中与您进行了一些扩展讨论之后:

MKOverlayView 的可重写函数(例如 canDrawMapRect)无法轻松追溯到它们的调用代码,因为该代码在 MapKit.framework 中的某个位置被混淆了。

相反,典型的方法是重新阅读他们的文档,直到您了解框架使用该函数的用途。 (有反编译二进制文件之类的东西,尽管这通常不受欢迎并且我不推荐它。)

canDrawMapRect 文档:http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009715-CH1-SW10

阅读他们的文档后,我推断:在 MapKit.framework 中的某个位置,在实际之前调用了 canDrawMapRect绘制视图。如果您没有在子类中重写该函数,它将调用超类的默认实现,该实现始终返回 YES,然后调用 drawMapRect: (如果您正在子类化 MKOverlayView,则必须重写该函数,否则什么都不会绘制!)

您上面链接的类可能会返回“否”。在这种特殊情况下,MapKit.framework 中的代码似乎会跳过调用 drawMapRect: 并且不会显示(或刷新)任何内容。

长话短说:对于这种情况,您必须扮演代码​​侦探的角色,并希望文档写得足够清楚,以便在无法看到所有代码的情况下找出答案。

编辑:只是为了进一步澄清 - 看来 MKOverlayView 必须进行子类化才能实际生成可见的内容。


在回答你的根本问题之前,我最初的回答是——

简短回答:这些是在该类中使用的私有函数。

长答案:在顶部的空名称类别中声明的函数
的实现文件仅对该类别所属的类可见
延伸。因此,这些函数只能在该范围内调用
类的实现。 (C++ 等价物只是声明
函数私有)

这 4 个函数中的 3 个是在同一个 .m 文件中调用的。没有
四处挖掘,我猜他们写了第一个函数,然后
后来决定不使用它。

After some extended discussion with you in comments:

The override-able functions of MKOverlayView, such as canDrawMapRect cannot easily be traced back to their calling code because that code is obfuscated somewhere in the MapKit.framework.

Instead, the typical approach is to re-read their documentation until you get a mental picture of what the framework is using the function for. (There is such a thing as decompiling binaries, although that is generally frowned upon and I do not recommend it.)

canDrawMapRect documentation: http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009715-CH1-SW10

After reading their documentation, I inferred this: Somewhere in the MapKit.framework, canDrawMapRect is being called prior to actually drawing the view. If you didn't override that function in your subclass, it calls the super-class's default implementation, which always returns YES and then calls drawMapRect: (Which MUST be overridden if you are subclassing MKOverlayView, or else nothing will draw!)

The class you linked above potentially returns NO. In that particular case, it appears the code in MapKit.framework skips calling drawMapRect: and nothing is displayed (or refreshed).

So, long story short: for this case, you have to play code-detective and hope the documentation is written clearly enough to figure it out without being able to see all of the code.

Edit: Just to further clarify - It appears MKOverlayView must be subclassed to actually generate something visible.


My original answer before getting to your underlying question --

Short answer: Those are private functions for use within that class.

Long answer: Functions declared in an empty-name category at the top
of implementation files are visible only to the class the category is
extending. Thus, those functions can only be called within that
class's implementation. (C++ equivalent would just be declaring the
functions private)

3 of those 4 functions are called within that same .m file. Without
digging around, I'm guessing they wrote the first function and then
later decided to not use it.

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