Ios – Combine UIPageViewController swipes with iOS 7 UINavigationController back-swipe gesture

iosios7objective c

I have a navigation controller that pushes a view-controller (PARENT) that contains an UIPageViewController (PAGES). Now I used pan/swipe gestures to switch between the children of the page-view-controller. However, I can no longer pop the PARENT-view controller using the swipe gesture from the left border of the screen, because it is interpreted as a gesture in PAGES.

Is it possible to accomplish that swipe-to-pop when the left-most view-controller is shown?

Two ideas:

  1. Return nil in pageViewController:viewControllerBeforeViewController -> doesn't work.

  2. Restrict the touch area, as described here.

Or is there a more straightforward way?

Best Answer

I had the same situation as @smallwisdom, but handled it differently.

I have a view controller A that I push on top of my navigation controller's stack. This view controller A contains a horizontal scroll view that stretches all the way from left side of the screen to the right.

In this scenario, when I wanted to swipe the screen to pop view controller A from navigation controller's stack, all I ended up doing was scrolling this horizontal scroll view.

The solution is pretty simple.

Inside my view controller A, I have code like this:

_contentScrollView = [[UIScrollView alloc] init];
[self.view addSubview:_contentScrollView];
for (UIGestureRecognizer *gestureRecognizer in _contentScrollView.gestureRecognizers) {
   [gestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
}

It works great. What this does? It is telling the scrollView's gesture recognizers that they have to wait to see if some other gesture recognizer will recognize the current gesture.

If that other fails to recognize, then they will no longer have to wait and they can try to recognize the current gesture.

If that other recognizer succeeds and recognizes the current gesture, then all of the gesture recognizers that have been waiting will automatically fail.

This other gesture recognizer they have to wait is set to be the navigation controller's interactivePopGestureRecognizer. He is in charge for the swipe-to-go-back gestures.

Related Topic