Transfer panning gestures to MKMapView

EDIT: Will it be clearer what I'm trying to achieve.

I have a few annotations on MKMapView that I want to easily drag and drop. Apple's standard way to move annotations is to tap once, and then quickly touch and hold and drag. App users complained that it was too hard to do.

So technically, what I would like to do is use the panorama gesture. The problem is that MKMapView also uses a pan gesture to move the map.

What I would like to do is when using the panorama gestures, check if the panorama gesture really approaches the annotation, if so, then let the pan gesture handler move the annotation. I am working on this part.

But if the pan gesture was not close to the annotation, then pas the gesture in MKMapView so that it is processed by it.

// EDIT END

I have a method for handling panorama gestures. This is called as I would expect when there is a panorama gesture on MKMapView. Sometimes I would not want to handle the gesture in my method, but to pass the gesture to MKMapView, to pan / drag the map, as usual.

Here is a diagram of what I still have. The transpose gesture is processed by the method:

-(void)panGesture:(UIPanGestureRecognizer*)sender

Depending on some logic, I would like to pass this gesture through MKMapView (self.mapView). Can someone share the code to do this, please?

I tried [self.mapView gestureRecognizerShouldBegin:sender];, but nothing happened from this call.

- (void) addPanGesture
{
    self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
    self.panGesture.delegate = self;
    [self.panGesture setMinimumNumberOfTouches:1];
    [self.panGesture setMaximumNumberOfTouches:1];
    [self.mapView addGestureRecognizer:self.panGesture];

}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer     shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer     *)otherGestureRecognizer
{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    BOOL result = NO;
    if ((gestureRecognizer == self.panGesture) && [[otherGestureRecognizer view] isDescendantOfView:[gestureRecognizer view]])
    {
        result = YES;
    }
    return result;
}

-(void)panGesture:(UIPanGestureRecognizer*)sender
{
    //some logic to see if we will handle the gesture in this method or pass gesture on to the MKMapView

    return;
}
+4
source share
2 answers

Apple - , . , .

..: (

, . , , . BTW, , , , . , . , / , , / . . , .

+1

iPatel: , Apple, .
, , ( ):

MapView PanGestureRecognizer ( builInPGR). , PanGestureRecognizer ( ownPGR) MapView.
UIGestureRecognizerDelegate , (. docs):

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, 
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool

false.

, , ownPGR. , builInPGR ownPGR.

true, ownPGR builInPGR : builInPGR , ownPGR , , , , , .

builInPGR, otherGestureRecognizer.
, ownPGR , , isEnabled of builInPGR false. builInPGR , .
, builInPGR.isEnabled true, ownPGR .

: , , . !

EDIT: , , Obj-C. , ( Obj-C), Obj-C.

0

Source: https://habr.com/ru/post/1687081/


All Articles