Use UIScreenEdgePanGestureRecognizer without moving MKMapView

I have a UIViewController containing MKMapView (actually it contains a full-screen container containing MKMapView, but it should not have any effect)

I implemented UIScreenEdgePanGestureRecognizer (to show the box) as follows:

self.swipeRight = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleEdgeGesture:)]; [self.swipeRight setEdges:UIRectEdgeLeft]; [self.swipeRight setDelegate:self]; [self.view addGestureRecognizer:self.swipeRight]; 

and for it to work, I had to add the following method (return YES):

 (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; 

But then the card moves simultaneously with the appearance of the box! I tried all kinds of tricks to prevent this, but could not ... (for example, I tried shouldBeRequiredToFailByGestureRecognizer or requireGestureRecognizerToFail )

Any idea how I could prevent MapView from moving when the gesture is ScreenEdgePan from LeftEdge?

+8
ios objective-c mkmapview uigesturerecognizer
source share
5 answers

What I did in my application was the following:

 UIScreenEdgePanGestureRecognizer *popRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePopRecognizer:)]; popRecognizer.edges = UIRectEdgeLeft; popRecognizer.delegate = self; 

Then set the delegate to YES, as you said

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

And enable / disable map scrolling as shown below.

 - (void)handlePopRecognizer:(UIScreenEdgePanGestureRecognizer*)recognizer { if(recognizer.state == UIGestureRecognizerStateBegan){ _mapView.scrollEnabled = NO; } else if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled){ _mapView.scrollEnabled = YES; } } 

Hope this helps.

+13
source share

The gesture on the map should be canceled as soon as the UIScreenEdgePanGestureRecognizer recognized. To do this, just set scrollEnabled to NO for a moment. This will cancel another gesture recognizer.

 - (void) handleEdgeGesture:(UIScreenEdgePanGestureRecognizer*)recognizer { if(recognizer.state == UIGestureRecognizerStateBegan) { // cancel simultaneous gesture on map view _mapView.scrollEnabled = NO; _mapView.scrollEnabled = YES; } } 
+3
source share
 - (void) handleEdgeGesture:(UIScreenEdgePanGestureRecognizer*)recognizer : (id)sender { if(recognizer.state == UIGestureRecognizerStateBegan && sender == GMSMapView) { // cancel simultaneous gesture on map view _mapView.isUserInteractionEnabled = NO; } } 
+1
source share

I believe that the quickest solution is to make a thin view (with a transparent background color) on top of mapView, where your gesture should not work on mapView. i.e enter image description here

+1
source share

The following combination worked for me without touching the map view.

 // This is to ensure UIScreenEdgePanGestureRecognizer won't be blocked by other gestures. // You may need to do some logic checking before returning YES. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } // This is to prevent other recognisers when UIScreenEdgePanGestureRecognizer // is recognising the gesture. Again, you may want to do some logic checking // before returning to YES. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; } 
+1
source share

All Articles