Detect A Pan Gesture in GMSMapView
Asked Answered
E

2

11

I have a GMSMapView that allows for a handful of gestures inside of it (pan, zoom, etc). I am trying to implement a Facebook style slide out menu from this view. What is the best way to detect a pan gesture from within this view while still allowing for all the other gestures to work properly? I'm sure there is a much better way to do this, but this is what I have so far? Any suggestions?

-(void)didPan:(UIPanGestureRecognizer*)gesture
{
    static BOOL g1 = NO;

    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        CGPoint location = [gesture locationInView:self];

    if(location.x < 90)
        g1 = YES;
    }

    if(gesture.state == UIGestureRecognizerStateChanged && g1)
    {
        CGPoint velocity = [gesture velocityInView:self];
        if(velocity.x > 0)
        {
            //Slide out menu
        }
        else
        {
            //Normal map view panning, zooming, etc.
        }  
    }
}
Euroclydon answered 16/8, 2014 at 11:38 Comment(0)
C
7

Paul de Lange has the right idea, but there are a couple of additional points to keep in mind.

You can't set gestures from GMSMapView to fail with requiresGestureRecognizerToFail: because those are hidden by the SDK. What you can do is modify the settings of your instance of GMSMapView. In particular, setting mapView.settings.scrollGestures = NO will stop the map from scrolling while you pan over.

Just remember to set it back to YES after the UIScreenEdgePanGestureRecognizer gesture is complete.

Compatible answered 27/6, 2015 at 5:24 Comment(0)
C
1

The UIScreenEdgePanGestureRecognizer might help you if you set the maps pan gesture to require the screen edge pan gesture recognizer to fail first with -requiresGestureRecognizerToFail:.

Alternatively implement the UIGestureRecognizerDelegate method -gestureRecognzierShouldBegin: for the g1 gesture recognizer and return NO if the point is less than 90 (as you do above).

Cyclopropane answered 26/6, 2015 at 7:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.