我試圖將MKMapView上的用戶默認位置註釋從藍色更改爲名爲geo的自定義圖像。當我設置斷點時,它會將它設置爲地理位置,但這兩個點(用戶默認和Passenger點都是默認的紅色精確定位註釋)我是否設置了錯誤,或者是否存在某些圖像規定?更改MKMapView用戶位置註釋
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKindOfClass(PassengerLocation) == false {
//User location
let userIdentifier = "UserLocation"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(userIdentifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:userIdentifier)
}
annotationView!.annotation = annotation
annotationView!.canShowCallout = true
// THIS IS NOT WORKING, DEFAULT RED PIN POINT STILL SHOWING
annotationView!.image = UIImage(named: "geo")
return annotationView
}
let identifier = "PassengerLocation"
if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) {
annotationView.annotation = annotation
return annotationView
} else {
let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:identifier)
annotationView.enabled = true
annotationView.canShowCallout = true
let btn = UIButton(type: .DetailDisclosure)
annotationView.rightCalloutAccessoryView = btn
return annotationView
}
}
你覺得如何? – 123FLO321