ios – MKOverlay更新闪烁

前端之家收集整理的这篇文章主要介绍了ios – MKOverlay更新闪烁前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,我使用MKPolyline来跟踪用户的路径.有时(并非所有时间,我不明白),当新的线段添加到地图时,整条线闪烁.有时却没有.这是用于添加行的代码

CLLocationCoordinate2D coords[2];

coords[0] = CLLocationCoordinate2DMake(newLocation.coordinate.latitude,newLocation.coordinate.longitude);

coords[1] = CLLocationCoordinate2DMake(oldLocation.coordinate.latitude,oldLocation.coordinate.longitude);

MKPolyline* line = [MKPolyline polylineWithCoordinates:coords count:2];

[mapView addOverlay:line];

我错过了什么吗?

编辑:这通常发生在应用程序从发送到后台返回时.我不确定为什么,因为我只是添加一个叠加层,而不是修改整个mapView.overlays数组. …对?

解决方法

这可能没有关系,但Apple确实在位置感知编程指南的 Managing the Map’s Overlay Objects部分说明了……

Because the map view is an interface item,any modifications to the
overlays array should be synchronized and performed on the application’s main thread.

猜你在找的iOS相关文章