0

I am working on my custom gesture on the map. It should work after 2s long press. All is fine, but after long press gesture I move fingers and map follows them... I need to escape this. I tried:

self.mapView.userInteractionEnabled = NO;

But it seems not working...

k06a
  • 17,755
  • 10
  • 70
  • 110
  • possible duplicate of [How to disable user interaction on MKMapView?](http://stackoverflow.com/questions/15418071/how-to-disable-user-interaction-on-mkmapview) – Desdenova Jan 06 '14 at 15:43
  • @Desdenova that answer does not work for me. Map gesture recognizers is working at moment I want to cancel them... – k06a Jan 06 '14 at 16:39

3 Answers3

1

Collect recognizers while our custom self.measureGestureRecognizer trying to recognize gesture:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (gestureRecognizer == self.measureGestureRecognizer)
    {
        if (self.otherGestureRecognizers == nil)
            self.otherGestureRecognizers = [NSMutableSet set];
        [self.otherGestureRecognizers addObject:otherGestureRecognizer];
    }
    return YES;
}

And when I need to cancel all Gesture Recognizers:

self.mapView.userInteractionEnabled = NO;
for (UIGestureRecognizer *gr in self.otherGestureRecognizers) {
    if (gr.enabled) {
        gr.enabled = NO;
        gr.enabled = YES;
    }
}
k06a
  • 17,755
  • 10
  • 70
  • 110
0

Working way. Collect all working on UIMapView gesture recognizers:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (gestureRecognizer == self.myLongPressGestureRecognizer
        && otherGestureRecognizer != self.myPanGestureRecognizer)
    {
        if (self.otherGestureRecognizers == nil)
            self.otherGestureRecognizers = [NSMutableSet set];
        [self.otherGestureRecognizers addObject:otherGestureRecognizer];
    }
    return YES;
}

And cancel them all when your gesture recognizer recognized:

- (IBAction)measureLongPressed:(UILongPressGestureRecognizer *)recognizer
{
    if (recognizer.state == UIGestureRecognizerStateBegan)
    {
        self.mapView.userInteractionEnabled = NO;
        for (UIGestureRecognizer *gr in self.otherGestureRecognizers)
        {
            gr.enabled = NO;
            gr.enabled = YES;
        }
        self.otherGestureRecognizers = nil;

        [self myLongPressDetectedAndMapFreezed];
        return;
    }
}
k06a
  • 17,755
  • 10
  • 70
  • 110
0

You can do something like this (Swift 4)

guard   let splitPanGesture = splitVc.view.gestureRecognizers?.first(where: { ($0 as? UIPanGestureRecognizer) != nil }),
        let mapPanGesture = mapView.subviews.first?.gestureRecognizers?.first(where: { ($0 as? UIPanGestureRecognizer) != nil }) else { return }

splitPanGesture.require(toFail: mapPanGesture)