Search code examples
iosios5mapkitmkoverlay

Add inverted circle overlay to map view


(Using iOS 5 and Xcode 4.2.)

I've followed the instructions here: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW15 and used the MKCircle and MKCircleView classes to add a circle overlay on my MKMapView.

However what I actually want is an inverted circle overlay, like the left map in the sketch below (currently I have a circle overlay like the one on the right):

Inverted and not-inverted circle overlay sketches

For the inverted circle, the overlay should cover the entire map - apart from the visible circle.

Is there an easy way to accomplish this using the MKCircle/MKCircleView classes? Or will I have to go deeper and define a custom overlay object/view?

Thank you for your help :)


Solution

  • The best way to do it, would be to subclass MKMapView and override the drawRect method call super, then paint over the map with the color you want. Then each time the user moves, drawRect should respond by drawing appropriately.