Forwarding a gesture to superview

870 Views Asked by At

So I have got this scenario:

-NavigationController
 -PageViewController
  -MapViewController
   -UIView
    -MKMapView (Full Screen)
  -OtherViewController

So basically, I want it to switch pages (viewcontrollers) when catching the UIScreenEdgeGesture. But having the map in one of them, this doesn't work properly.

I have researched a lot (!) about this but still haven't found the right solution.

I believe that the correct approach here is to delegate this gesture to the nextResponder in the hierarchy.

So I have successfully captured the gesture when the user swipes on the left edge of the screen.

Right now my issue is I can't manage to pass the gesture to the UIView (MKMapView.superview). I have two questions :

// 1. How to do it // 2. Is this the right approach?

Let me know your thoughts on this one please!

EDIT 1: Adding some code and Images of story board

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

[self.mapView addGestureRecognizer:popRecognizer];

enter image description here

EDIT 2: I want this behaviour : Use UIScreenEdgePanGestureRecognizer without moving MKMapView

But when the gesture is recognized, I want it to switch to the page on the left (OtherViewController)

FINAL EDIT: THE workaround that I've come up with consists in putting a clear view on top of the map, leading to the desired behaviour. Not happy with the solution, but it works for now.

enter image description here

1

There are 1 best solutions below

2
On

When you create your gesture, make the target the superview, and call the method in the superview for the action, something like:

    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:[self.view superview] action:@selector(swipeHandler:)];

Don't know if MKMapView.superview would work, that depends on if MKMapView is an instance. Hard to know what you're referring to without code.