Pop View Controller Using Screen Edge Pan Gesture Recogniser Not Following the Thumb

Pop view controller using Screen edge pan gesture recogniser not following the thumb

There's no need to add Edge Pan Gesture Recogniser. Following @beyowulf's suggestions I've been able to implement the swipe to go back feature that behaves the same way as the default system implementation does - the views edge follows my thumb as I swipe it to dismiss it.

So I've removed the ScreenEdge Pan Gesture Recogniser from the storyboard and also removed the related @IBAction.

I've made my first view controller to be the delegate for interactivePopGestureRecognizer. Here's the code:

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
navigationController?.interactivePopGestureRecognizer?.delegate = self
}
}

extension ViewController: UIGestureRecognizerDelegate {

func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
return navigationController?.viewControllers.count > 1 ? true : false
}
}

How to handle a UIScreenEdgeGestureRecognizer with a map view covering the whole view?

What I did was to add a view with a 10pt width and clear color background over the edge I needed the gesture recognizer and I added the gesture recognizer to this view.

In the picture, the white rectangle on the right is the view which will have the gesture recognizer. You should change the background color to clear color.

A way to add a UIScreenEdgePanGestureRecognizer on a map view

The view outlet:

@property (weak, nonatomic) IBOutlet UIView *rightEdgeGestureView;

Add the gesture recognizer to the view on the screen right edge:

- (void)setupGestureRecognizer {

UIScreenEdgePanGestureRecognizer *gestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)];
gestureRecognizer.edges = UIRectEdgeRight;
[_rightEdgeGestureView addGestureRecognizer:gestureRecognizer];
}

Is there a way to call a function once a View Controller leaves the view stack?

Yes, I can think of few ways to do this off the top of my head

One option would be to add some code to a dealloc method of the UIViewController.

If you don't expect the view controller controller to get deallocated when it leaves the stack you can also set a UINavigationControllerDelegate for the UINavigationController and define

func navigationController(_ navigationController: UINavigationController,
didShow viewController: UIViewController,
animated: Bool) {
guard let poppedViewController =
navigationController.transitionCoordinator?.viewController(forKey: .from)
<Do something with the popped VC>

GestureRecogniser not working when going back

Call [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; in viewWillAppear instead of viewDidLoad so that it is replaced following each transition. A gesture can only be attached to one view at a time so when you attach it to a different view it gets removed from the first.

Alternatively, consider adding the gesture to a more root view (like the window / navigation bar) depending on what interaction you want to enable.



Related Topics



Leave a reply



Submit