【问题标题】:How can I remove all annotations on my MkMapView that are not currently visible on iOS 8如何删除我的 MkMapView 上当前在 iOS 8 上不可见的所有注释
【发布时间】:2015-08-18 11:46:36
【问题描述】:

在 iOS 8 上使用 Swift 1.2 在我的 MkMapView 上可见一些注释。现在,如果用户在地图上滚动,我想删除所有当前不可见的注释。

我该怎么做?

【问题讨论】:

  • 你读过我的问题吗?我知道如何删除注释。我想知道如何删除当前不可见的注释..

标签: ios swift annotations mkmapview


【解决方案1】:

首先获取当前可见的mapRect:

let visRect = mapView.visibleMapRect

现在您可以获取该矩形内的所有注释:

let inRectAnnotations = mapView.annotationsInMapRect(visRect)

最后一步是遍历所有注释并检查您的注释是否在这些注释中

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

【讨论】:

    猜你喜欢
    • 2011-03-02
    • 1970-01-01
    • 2011-01-09
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 2012-08-09
    • 2015-01-11
    相关资源
    最近更新 更多