Sie müssen eine benutzerdefinierte Klasse erstellen, die von MKMapView abgeleitet ist. Diese Klasse muss das Protokoll MKMapViewDelegate
implementieren.
Dann brauchen Sie 2 Schritte: Erstellen Sie das Annotation-Objekt und erstellen Sie eine Ansicht für diese Annotation.
Annotation erstellen:
Irgendwo in Ihrem Code auf Ihre Bedürfnisse ab:
let annotation = MKPointAnnotation()
annotation.setCoordinate(location) // your location here
annotation.title = "My Title"
annotation.subtitle = "My Subtitle"
self.mapView.addAnnotation(annotation)
die Ansicht Anmerkung erstellen
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKPointAnnotation {
let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")
pinAnnotationView.pinColor = .Purple
pinAnnotationView.draggable = true
pinAnnotationView.canShowCallout = true
pinAnnotationView.animatesDrop = true
return pinAnnotationView
}
return nil
}
Vielen Dank !!! : D –