• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
MKMapView pin dragging question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: MKMapView pin dragging question
      • From: Alex Zavatone <email@hidden>
  • Prev by Date: Re: [ANN] Nursery Framework 1.0.1 (build with Xcode 9) released
  • Next by Date: Re: MKMapView pin dragging question
  • Previous by thread: Re: Register media source to system
  • Next by thread: Re: MKMapView pin dragging question
  • Index(es):
    • Date
    • Thread