Ich habe eine linke Taste zu meinem MKAnnotation
hinzugefügt. Ich möchte, dass es dies ebenso zeigt wie die richtige Schaltfläche und die Bilder, die ich unten eingestellt habe. Dieser Code unten zeigt beide Tasten, erkennt aber nur die rechte Maustaste auf mein Segment für NewEntry
. Wie kann die calloutAccessoryControl
angegeben werden, um die linke Taste angezapft zu erkennen, sowie die rechte Taste angetippt, und fügen Sie den zusätzlichen Übergang von der linken Taste zu "links Detail" für meine LeftButtonDetailViewController
?wie man vom 2. Knopf auf MKannotation übergeht?
Hier ist mein Code:
//MARK: - MKMapview Delegate
extension MapViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
guard let subtitle = annotation.subtitle! else { return nil }
if (annotation is SpecimenAnnotation) {
if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(subtitle) {
return annotationView
} else {
let currentAnnotation = annotation as! SpecimenAnnotation
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: subtitle)
switch subtitle {
case "Uncategorized":
annotationView.image = UIImage(named: "IconUncategorized")
case "Documentaries":
annotationView.image = UIImage(named: "IconDocumentaries")
default:
annotationView.image = UIImage(named: "IconUncategorized")
}
annotationView.enabled = true
annotationView.canShowCallout = true
let detailDisclosure1 = UIButton(type: UIButtonType.DetailDisclosure)
let detailDisclosure2 = UIButton(type: UIButtonType.InfoDark)
annotationView.rightCalloutAccessoryView = detailDisclosure1
annotationView.leftCalloutAccessoryView = detailDisclosure2
if currentAnnotation.title == "Empty" {
annotationView.draggable = true
}
return annotationView
}
}
return nil
}
func mapView(mapView: MKMapView, didAddAnnotationViews views: [MKAnnotationView]) {
for annotationView in views {
if (annotationView.annotation is SpecimenAnnotation) {
annotationView.transform = CGAffineTransformMakeTranslation(0, -500)
UIView.animateWithDuration(0.5, delay: 0.0, options: .CurveLinear, animations: {
annotationView.transform = CGAffineTransformMakeTranslation(0, 0)
}, completion: nil)
}
}
}
func mapView(mapView: MKMapView, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if let specimenAnnotation = annotationView.annotation as? SpecimenAnnotation {
performSegueWithIdentifier("NewEntry", sender: specimenAnnotation)
}
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, didChangeDragState newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState) {
if newState == .Ending {
view.dragState = .None
}
}
}
By the way, wenn 'dequeue' in' viewForAnnotation 'erfolgreich, bevor Sie die' annotationView' zurückgeben, müssen Sie die 'annotation' der Ansicht als 'annotation' festlegen, die an diese Methode übergeben wurde. Sie sollten auch jede andere notwendige Konfiguration durchführen, die sich für die neue "Annotation" ändern könnte (z. B. das Setzen des "ziehbaren" auf der Basis des "Titels"). – Rob