简体   繁体   English

如何删除MkMapView上当前在iOS 8上不可见的所有注释

[英]How can I remove all annotations on my MkMapView that are not currently visible on iOS 8

have a few annotations visible on my MkMapView using Swift 1.2 on iOS 8. Now if the user scrolls around the map, I'd like to remove all annotations, that are currently not visible. 在iOS 8上使用Swift 1.2在MkMapView上有一些可见的注释。现在,如果用户在地图上滚动,我想删除当前不可见的所有注释。

How can I dow this? 我该怎么做?

First get the currently visible mapRect: 首先获取当前可见的mapRect:

let visRect = mapView.visibleMapRect

now you can get all annotations within that rect: 现在您可以获得该矩形内的所有注释:

let inRectAnnotations = mapView.annotationsInMapRect(visRect)

last step would be to iterate over all annotations and check if you annotation is in these annotations 最后一步是遍历所有注释,并检查您的注释是否在这些注释中

for anno : MKAnnotation in mapView.annotations {
  if (inRectAnnotations.contains(anno)) {
    //do what you want to do with the annotation (hide/remove)
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM