开发者

Confusion about MKOverlayView

开发者 https://www.devze.com 2023-03-22 21:17 出处:网络
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'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 the开发者_如何学运维se 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消