2017-10-14 6 views
-1

callOutView을 사용자 정의하고 AnnotationViewtheGreatAnnotationView이라는 고유 번호를 만들었지 만지도에 표준 Annotation Pin을 유지하려고합니다. 이 코드에서는 사용자 정의 주석 이미지 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

'이미지'대신 표준 핀을 사용하려면 'MKPinAnnotationView'를 사용해야합니다. – Rob

답변

0

대신 MKAnnotationViewMKPinAnnotationView 사용해야합니다.

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

답변 해 주셔서 감사합니다. 모든 annotation에 대해 theGreatAnnotationView를 사용하고 싶지만 (annotation의 callOutView 때문에), 모든 주석에 대해 standart Annotation Pin 이미지를 원한다. 따라서 두 가지 경우는 없습니다. – TheRJI

관련 문제