2017-10-14 11 views
-1

J'ai personnalisé mon callOutView, en créant un AnnotationViewtheGreatAnnotationView, mais je veux conserver la broche d'annotation standard sur la carte. Dans ce code, j'utilise une image d'annotation personnalisée view?.image = annotation.image mais lorsque la ligne est supprimée, il n'y a pas d'annotation sur ma carte. Pouvez-vous m'aider à résoudre ce problème?Comment utiliser le symbole MKAnnotation standard avec un MKAnnotationView fait sur mesure

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

Si vous voulez une broche standard sur votre carte plutôt qu'une 'image', vous devez utiliser' MKPinAnnotationView'. – Rob

Répondre

0

Vous devez utiliser MKPinAnnotationView au lieu de 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

Merci pour votre réponse. Je veux utiliser monGreatAnnotationView pour chaque annotation (à cause de la callOutView des annotations), mais je veux toujours l'image standart Annotation Pin pour chaque annotation. Donc, il n'y a pas deux cas. – TheRJI