关于 MKOverlayView 的困惑
我一直在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在评论中与您进行了一些扩展讨论之后:
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 必须进行子类化才能实际生成可见的内容。
在回答你的根本问题之前,我最初的回答是——
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-SW10After 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 callsdrawMapRect:
(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 --