Black and white overlay for an MKMapView

前端 未结 2 1066
臣服心动
臣服心动 2021-01-12 21:07

I have an MKMapView and am adding an overlay (MKOverlay) to it.

I would like the overlay to make the map view underneath to appear black & white (i.e. monochrom

2条回答
  •  醉梦人生
    2021-01-12 22:05

    The most proper route, which sadly isn't yet available on iOS would be:

    Your MKOverlay is at some point being used to create an MKOverlayView, which will have a CALayer as it descends from UIView. You can attach CIFilters as compositingFilters to CALayers, which dictate how the view is composited with the background. You could attach a filter of type CIColorMonochrome to that.

    Because that option isn't available, you're going to have to leap through some major hurdles to do the work for yourself. You'll probably need to implement your own custom MKOverlayView that in its drawView uses the techniques given in Apple's QA1703 to get the pixel contents of the map view in the relevant area (be careful not to end up in an infinite recursive loop though), transform those into black and white and present them as your view.

    Is that something it's worth investigating further or would you be happier to substitute the effect than to really delve into this stuff?

提交回复
热议问题