2017-05-27 1 views
0

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 
     } 
    } 

Antwort

1

In Ihrer viewFor annotation Funktion diese Zeile am Anfang hinzufügen:

if annotation is MKUserLocation { 
    return nil 
} 

Weil Sie die MKUserLocation wenn Es ist alles tun möchte nicht, dass zu.

+0

Setze ich diese Zeile anstelle von "if! (Anmerkung ist MKUserLocation)"? –

+1

Ja können Sie @DanielC. –

+0

Es funktioniert! Danke! –

Verwandte Themen