Gradient along MKPolyLineView ( MKPolylineRenderer )

久未见 提交于 2019-11-29 12:58:59

问题


I'd like to apply a gradient on a polyline view depending on some conditions like speed. I was able to subclass MKPolyLineRenderer to draw with custom stroke and fill, but only with the same color along the path.

I saw other similar questions like : Draw segments from a circle or donut or On OSX, how do I gradient fill a path stroke? , but it is not exactly what I'd want. If I understand correctly, a path like below couldn't be filled with these methods. At least not treated as a whole.

A very similar question is Gradient Polyline with MapKit ios. But it adds an overlay for each segment between the points, which I think isn't too efficient.

Is this the only possible way ? ( I'd need to draw hundreds or maybe thousands of these segments ... ) How can this be achieved easily ?

Thanks


回答1:


So the original answer is here https://stackoverflow.com/a/20159374/2606068

you can find the demo here https://github.com/wdanxna/GradientPolyline

and some improvement tips provided by @Templar is:

  • prepare the path directly in the init.
  • check also for CGRectContains, not only for intersection.

thanks man! :p



来源:https://stackoverflow.com/questions/20247313/gradient-along-mkpolylineview-mkpolylinerenderer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!