【发布时间】:2013-01-20 21:53:40
【问题描述】:
我正在制作一张包含 5000 多个图钉的地图。每次我更改区域时,我都会根据缩放程度添加或删除 annotationViews。
唯一的问题是这个(极端测试):
当引脚之间的空间不多时,标注会移动到顶部,但通常红色引脚会在顶部。
我只使用基本的 MKPinAnnotationView。没有自定义标注。
我确实尝试通过 Aaron Z-ordering of MKAnnotationViews 实现 Z-ordering-category,但似乎没有帮助。
编辑:
我还没有解决,但我确实有一些想法。
MapKit 写得不好。 MapView 有责任对视图进行排序,因此至少选定的视图保持在顶部。
可能是 mapView 需要处理的注解太多了。
如何复制
只需添加 5000 个注释。
-(void)addAnnotations
{
NSMutableArray *annotations = [NSMutableArray array];
for(int i=0;i<5000;i++) {
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
CGFloat lat = 59.189358;
CGFloat lng = 18.267839;
CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};
DTSAnnotation *annotation = [DTSAnnotation annotationWithCoord:newCoord];
[annotation setTitle:@"."];
[annotations addObject:annotation];
}
[[self mapView]addAnnotations:annotations];
}
【问题讨论】:
-
解决它的一种巧妙方法是添加 mapView:didSelectAnnotationView: 并调用 [view.superview bringSubviewToFront:view];并将注释视图推回 mapView:viewForAnnotation: 当您添加它时。您应该将这些引脚聚集在一起,很难选择一个。
-
感谢您的精彩提示!
标签: ios ios6 mapkit mkannotationview