Я добавил левую кнопку к моему MKAnnotation
. Я хочу, чтобы он показывал это, а также правую кнопку и изображения, которые я установил ниже. Этот код ниже показывает обе кнопки, но только распознает правую кнопку, нажмите на мой сегмент для NewEntry
. Как указать calloutAccessoryControl
, чтобы распознать левую кнопку нажатой, а также правую кнопку нажатой, и добавить дополнительный переход от левой кнопки к «левой детали» для моего LeftButtonDetailViewController
?как перейти от 2-й кнопки на MKannotation?
Вот мой код:
//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
}
}
}
Кстати, если 'dequeue' в' viewForAnnotation', перед тем как вы вернете «annotationView», вы должны установить «аннотацию» представления как «аннотацию», которая была передана этому методу. Вы также должны выполнить любую другую необходимую конфигурацию, которая может измениться для новой «аннотации» (например, установка «draggable» на основе «title»). – Rob