沿MKPolyLineView(MKPolylineRenderer)的渐变 [英] Gradient along MKPolyLineView ( MKPolylineRenderer )
问题描述
我想根据速度等条件在折线视图上应用渐变。
我能够继承 MKPolyLineRenderer
来绘制自定义笔触和填充,但只沿路径使用相同的颜色。
我看到其他类似的问题,如:
你可以在这里找到演示 https://github.com/wdanxna/GradientPolyline
以及@Templar提供的一些改进提示是:
- 直接在init中准备路径。
- 同时检查CGRectContains,不仅仅是交集。
谢谢你! :p
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
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
这篇关于沿MKPolyLineView(MKPolylineRenderer)的渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!