Reputation: 35
Any idea why the following:
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.annotation = annotation
pinView!.canShowCallout = false
pinView!.draggable = true
Allows for a draggable annotation that will snap back to the user location while the following:
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.annotation = annotation
pinView!.canShowCallout = false
pinView!.draggable = true
Does not snap back to the user location.
This is being implemented within the viewForAnnotation function that allows you to change the current location pin.
I'm trying to edit the pin for a user location and I want it to be draggable but I want it to snap back to the user location when one is done dragging. It only does it within the MKPinAnnotationView but I need it to work for the MKAnnotatioView. Thanks for the help!
Upvotes: 3
Views: 316
Reputation: 2881
I think it is just how the subclass is implemented unfortunately.
I think the work around is to use something like:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding)
{
//reset CLLocationCoordinate2D of MKAnnotation to the old coordinate (i.e. where the annotation view was before dragging)
}
}
Note that I think to refresh the annotation, you might have to remove the annotation and add it back. The pins are a lot easier to manage, but I know that they are not as easy to customize.
Upvotes: 1