Ich arbeite mit MapKit und ich änderte das Bild der Annotation, aber das Problem ist, die Userlocation (blauer Punkt) änderte auch sein Bild (ich wollte das nicht). Wie kann ich es wieder normal wiederherstellen? Außerdem habe ich dem Callout einen kleinen Knopf hinzugefügt, der (wie Sie vielleicht schon vermutet haben) zu meinem Standort hinzugefügt wurde und nicht dort sein sollte. Mein Code ist der folgende ...(MapView) Userlocation Bild geändert Hilfe zum Wiederherstellen
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is MKUserLocation) {
print("annotation is MKUserLocation")
}
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "identifier")
if annotationView == nil{
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "identifier")
annotationView!.canShowCallout = true
annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
let pinImg = UIImage(named: "curz")
let size = CGSize(width: 50, height: 50)
UIGraphicsBeginImageContext(size)
pinImg!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
annotationView!.image = resizedImage
}
else {
annotationView!.annotation = annotation
}
return annotationView
}
//Var SelectedAnnotation
var anotacionSeleccionada : MKPointAnnotation!
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
anotacionSeleccionada = view.annotation as? MKPointAnnotation
performSegue(withIdentifier: "vista", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? ViewController {
destination.pin = anotacionSeleccionada
}
}
Setze ich diese Zeile anstelle von "if! (Anmerkung ist MKUserLocation)"? –
Ja können Sie @DanielC. –
Es funktioniert! Danke! –