2017-10-14 7 views
-1

callOutViewをカスタマイズしてAnnotationViewtheGreatAnnotationViewを作成しましたが、標準アノテーションピンをマップに残したいと思います。このコードでは、カスタム注釈画像view?.image = annotation.imageを使用していますが、その行を削除すると、マップに注釈はありません。この問題を解決するのを手伝ってもらえますか?カスタムMKAnnotationViewで標準MKAnnotation Symbolを使用する方法

func mapView(_ surroundingMapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

    var annoView: MKAnnotationView? 
    if annotation.isKind(of: MKUserLocation.self) { 

     return nil 
    } 



    var view = surroundingMapView.dequeueReusableAnnotationView(withIdentifier: "imageAnnotation") 
    if view == nil { 
     view = theGreatAnnotationView(annotation: annotation, reuseIdentifier: "imageAnnotation") 
     reuseIdentifier: "imageAnnotation") 
     view!.canShowCallout = false 

    } 

    let annotation = annotation as! Artwork 


    view?.image = annotation.image 
    view?.annotation = annotation 


    return view 
} 
+0

'image'ではなくマップに標準ピンが必要な場合は、' MKPinAnnotationView'を使用してください。 – Rob

答えて

0

あなたはMKPinAnnotationViewの代わりMKAnnotationViewを使用する必要があります。

func mapView(_ surroundingMapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

    var annoView: MKAnnotationView? 
    if annotation.isKind(of: MKUserLocation.self) { 

     return nil 
    } 

    if /* if annotation is image */ { 
     var view = surroundingMapView.dequeueReusableAnnotationView(withIdentifier: "imageAnnotation") 
     if view == nil { 
      view = theGreatAnnotationView(annotation: annotation, reuseIdentifier: "imageAnnotation") 
      view!.canShowCallout = false 

     } 

     let annotation = annotation as! Artwork 


     view?.image = annotation.image 
     view?.annotation = annotation 
    } else { 
     /* if annotation is pin */ 
     var view = surroundingMapView.dequeueReusableAnnotationView(withIdentifier: "pinAnnotation") 
     if view == nil { 
      view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pinAnnotation") 
      view!.canShowCallout = false 
     } 

     let annotation = annotation as! Artwork 


     view?.annotation = annotation 
    } 

    return view 
} 
+0

ありがとうございます。注釈のcallOutViewのためにすべての注釈に対してtheGreatAnnotationViewを使用したいと思いますが、すべての注釈に対してstandart注釈ピン画像が必要です。したがって、2つのケースはありません。 – TheRJI

関連する問題