2016-12-02 1 views
0

PhotoAnnotation은 MKAnnotation을 따르고 PhotoAnnotationView는 MKAnnotationView의 하위 클래스입니다. PhotoAnnotation에 이미지 속성이 있습니다.은 사용자 지정 AnnotationView의 이미지를 즉시 표시 할 수 없습니다.

일단 내가 앱을 열면 사용자 정의 주석의 이미지가 mapview에 표시되지 않습니다. 나는 주변을 돌고 어딘가로 움직여야 만하고, 다시 원래의 영역으로 돌아 가면 이미지가 보여 질 것입니다.

MKPinAnnotation을 사용하면 이러한 문제가 없습니다. 핀의 이미지가 곧바로 표시됩니다.

나는 그것을 고치는 방법에 대한 단서가 없습니다. 도와주세요. 정말 고마워. 이 부분, 'view.image = 전무'의

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
    if let annotation = annotation as? PhotoAnnotation { 
     let identifier = "pin" 
     let view: PhotoAnnotationView 
     if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? PhotoAnnotationView { 
      dequeuedView.annotation = annotation 

      dequeuedView.image = annotation.image 

      view = dequeuedView 
     } else { 
      view = PhotoAnnotationView(annotation: annotation, reuseIdentifier: identifier) 
      view.canShowCallout = false 
      view.image = nil 
     } 
     return view 
    } 
    return nil 
} 

답변

0

를 적어 둡니다는 ... 어떤 주석이 아직 이전에 만들어지지가 첫 번째 부하에 있기 때문에, 당신이 전무로 이미지를 설정하는 코드에 떨어진다. 그걸 처리하면 네가 잘된거야.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
    if let annotation = annotation as? PhotoAnnotation { 
     let identifier = "pin" 
     let view: PhotoAnnotationView 
     if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? PhotoAnnotationView { 
      dequeuedView.annotation = annotation 

      dequeuedView.image = annotation.image 

      view = dequeuedView 
     } else { 
      view = PhotoAnnotationView(annotation: annotation, reuseIdentifier: identifier) 
      view.canShowCallout = false 
      view.image = UIImage() // do something here... 
     } 
     return view 
    } 
    return nil 
} 
+0

여전히 작동하지 않습니다. –

+0

다른 이미지를 추가, 지금은 작업입니다. 덕분에 –

+0

문제 없습니다. 천만에요. 이미 답변 된 경우 질문에 답변으로 표시하십시오. – nferocious76

관련 문제