UIPanGestureRecognizer on MKMapView?

后端 未结 1 1225
无人及你
无人及你 2020-12-04 19:37

I would like to add some logic when user moves with map view i. e. he does a pan touch. But when I add the gesture recognizer and I want to log the touch, nothing happens.

相关标签:
1条回答
  • 2020-12-04 20:00

    Ok, because no one knew, I had to spent one Apple technical support consult for it. ;o)

    Because MKMapView evidently has its own recognizers to interact with user, you have to adhere to the UIGestureRecognizerDelegate protocol and implement (BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: like this:

    - (void)viewDidLoad
    {
        ...
        UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(showPan)];
        panGesture.delegate = self;
        [appDelegate.mapView addGestureRecognizer:panGesture];
        [panGesture release];
    }
    
    - (void)showPan
    {
        NSLog(@"pan!");
    }
    
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {   
        return YES;
    }
    

    Then it works like a charm.

    0 讨论(0)
提交回复
热议问题