(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):
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 :)
i tried to use this swift version and it didn't work, so im posting my implementation (tested on iOS 12)
Here a Swift version. Thanks Valerii.
https://github.com/dariopellegrini/MKInvertedCircle
The best way to do it, would be to subclass
MKMapView
and override thedrawRect
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.I had the same task and here is how I solve it:
NOTE: this code will only work starting from iOS7
Add an overlay to the map, somewhere in your view controller:
In the MKMapViewDelegate methods write next:
The MyMapOverlay itself should be something like followed:
And the MyMapOverlayRenderer:
As a result you will have exact same view like on the left image that was posted in the question.