0
PhotoAnnotation符合MKAnnotation,PhotoAnnotationView是MKAnnotationView的子類。 PhotoAnnotation具有圖像屬性。無法立即顯示自定義AnnotationView的圖像
問題是一旦我打開應用程序,自定義註釋的圖像不會顯示在mapview上。我必須平移並移動到某個地方,然後移回原始區域,然後圖像纔會顯示出來。使用MKPinAnnotation的
沒有這樣的問題。銷的圖像將立即顯示。
我不知道如何解決它。請幫幫我。非常感謝。
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
}
仍然不起作用。 –
我添加其他圖片,現在是工作。謝謝 –
沒問題。別客氣。只要將問題標記爲已回答的問題。 – nferocious76