Frage

I'm looking to create a 'long hold' pin drop on an MKMapView.

Currently, everything works to the way I want it, when you tap and hold on the Map, it registers the gesture and the code drops a pin.

-(void)viewDidLoad
{
   [self.mapView addGestureRecognizer:longPressGesture];
}

-(void)handleLongPressGesture:(UIGestureRecognizer*)sender
{
    if(sender.state == UIGestureRecognizerStateBegan || sender == nil)
    {
        CGPoint point = [sender locationInView:self.mapView];
        
        CLLocationCoordinate2D locCoord;
        locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
        
        //Drop Pin
    }
}

That is, however, it only works if you are not too close to the MKUserLocation annotation (the Blue pulsing dot) otherwise the gesture does not get registered, and the didSelectAnnotationView: function gets called.

Is there a way to Ignore the user taping the MKUserLocation annotation? I was looking for something like setUserEnabled but it doesn't exist for MKAnnotations.

War es hilfreich?

Lösung

The MKAnnotationView class has an enabled property (not the id<MKAnnotation> objects).


To set enabled on the map view's user location annotation view, get a reference to it in the mapView:didAddAnnotationViews: delegate method:

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *av = [mapView viewForAnnotation:mapView.userLocation];
    av.enabled = NO;  //disable touch on user location
}


(In viewForAnnotation, you have to return nil to tell the map view to create the view itself so enabled can't be set there -- at least for the user location.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top