MKMapView pin dragging question
MKMapView pin dragging question
- Subject: MKMapView pin dragging question
- From: Marco S Hyman <email@hidden>
- Date: Wed, 25 Oct 2017 18:08:20 -0700
I'm not sure what I'm doing wrong or failing to do, but I can't get a map pin
annotation to drag. Instead I'm dragging the entire map.
Pin is created and placed on a map using this code:
mapPin = MKPointAnnotation()
if let pin = mapPin {
pin.coordinate = location;
pin.title = "location"
mapView.addAnnotation(pin)
}
This MKMapViewDelegate function is called to create the annotationView
func mapView(_ mapView: MKMapView,
viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "pinAnnotation"
var annotationView =
mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as?
MKPinAnnotationView
if (annotationView == nil) {
annotationView = MKPinAnnotationView(annotation: annotation,
reuseIdentifier: identifier)
if let av = annotationView {
av.pinColor = .red;
av.animatesDrop = false
av.canShowCallout = false
av.isDraggable = true
} else {
unexpected(error: nil, "Can't create MKPinAnnotationView")
}
} else {
annotationView!.annotation = annotation
}
return annotationView
}
However, a breakpoint on the the delegate function that should be called
durring a drag operations is never triggered.
// A pin is being dragged.
func mapView(_ mapView: MKMapView,
annotationView view: MKAnnotationView,
didChange newState: MKAnnotationViewDragState,
fromOldState oldState: MKAnnotationViewDragState) {
// ...
}
What did I forget?
High Sierra (10.13)
Xcode 9.0.1 (9A1004)
I'm attempting to drag using a three finger gesture on a tablet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden