2017-11-10 11 views
0

注:私はiOS11sのネイティブmapview注釈クラスタリングを使用しています。注釈はまだ最大ズームでクラスタ化されている状況ではMKClusterAnnotationコールアウトを表示することはできますか?

、どのような方法で、私たちはコールアウトを表示することができますか?

クラスタでアノテーションのリストを表示するためのポップオーバータイプの表示を示していますが、selectAnnotationを呼び出すだけでは、「クラスタ化された」アノテーションのコールアウトを表示するには不十分です。

「何か」が選択されていますが、何の吹き出しが表示されません。何かによって、私はマップビューに触れると私のdidDeselect viewメソッドが呼び出されたことを意味します。

答えて

0

私は同じ問題を駆け抜けました。その場合、彼らは注意深く考えなかったようです。クラスタ化されたMKAnnotationではなく、MKClusterAnnotationを選択する必要がありますが、そこに到達するのは簡単ではありません。

If non-nil this is the annotation view this view is clustered into.

は、だから私のMKAnnotationViewサブクラスに私がするsetSelectedメソッドをオーバーライドしてのMapViewに弱い参照して、あなたが選択する必要があります。MKAnnotationViewのプロパティがありますiOS11に

は、ドキュメントの状態としてあることclusterと呼ばれますクラスタ1:

//You have weak reference to mapView 
weak var mapView: MKMapView? 

override func setSelected(_ selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 
    if #available(iOS 11.0, *) { 
     if selected, let cluster = cluster { 
      // Deselect the current annotation (Maybe this step is not required, didn't check it) 
      if let annotation = annotation { 
       mapView?.deselectAnnotation(annotation, animated: false) 
      } 
      // Select the cluster annotation 
      if let clusterAnnotation = cluster.annotation { 
       mapView?.selectAnnotation(clusterAnnotation, animated: true) 
      } 
     } 
    } 
}