how to update MKPolyline / MKPolylineView?

橙三吉。 提交于 2019-12-18 03:57:11

问题


I am trying to create a polyline (MKPolyline) overlay that updates periodically, to simulate the movement of an object. I can achieve this by removing the old overlay, updating the polyline and adding the overlay again, but this leads to flickering.

For a point annotation (MKPointAnnotation) you can simply change its coordinate, and the view will be updated automatically and smoothly without having to remove and re-add the annotation.

Is this also possible somehow for an overlay?


回答1:


yea, you would have to add an additional overlay with the point set of from your last point to your next point. Once you create the MKPolyline with your points, your not able to change it when it draws the MKPolylineView without removing the old and adding the newly created one.

you could create a new polyline view with all the points (including the new one) and add it to the map but do not remove the older one. then once the new one is added, you can remove the older shorter one. It might not be pretty to implement but it should get rid of the flashing on updates. you can distinguish the old and the new with a tag. maybe a point count as the tag would work.




回答2:


All of the MapKit overlays are immutable so in order to get mutability you need to build your custom overlay and redraw only the region that needs to be updated.

You can find an example in the Breadcrumb sample application example from Apple. Breadcrumb link




回答3:


The MKPolyline class inherits MKMultiPoint, which consists of a set of points. This is a property that is read-only, meaning, unfortunately, you can't update it.



来源:https://stackoverflow.com/questions/3171572/how-to-update-mkpolyline-mkpolylineview

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