title: Disable temporarily forward swipe only in uiPageViewController
body: <p>I'm writing a series of settings / setup screens using uiPageViewController (images at the bottom). The user configures stuff, and swipe to the next screen, and so on. But I would like to lock / disable / block the forward swipe until the settings has been accomplished by the user in the current screen. </p>
  
  <p>I tried:</p>
  
  <p>1) uiPageViewController.view.userInteractionEnabled = false. It blocks everything in the screen, including the backward swipe. I want to block only the forward.</p>
  
  <p>2)</p>
  
  <pre><code>func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -&gt; UIViewController? {
      if !forwardSwipeEnabled {
          return nil
      }
      var index  = contentViewControllers.indexOf(viewController)
      index += 1
      return contentViewControllers[index]
  }
  </code></pre>
  
  <p>to <code>return nil</code> when <code>forwardSwipeEnabled</code> is set to <code>false</code>, and it works, but the forward swipe remains blocked even after I change forwardSwipeEnabled = true because UIPageViewController already called this function when the scene showed up on the screen. </p>
  
  <p>If I go back and forward again, the function gets called again and it works. </p>
  
  <p><strong>----- edit -----</strong></p>
  
  <p>Calling <code>pageViewController!.setViewControllers(viewControllers, direction: .Forward, animated: false, completion: nil)</code> with the current view controller doesn't refresh or call the function again.</p>
  
  <p>3) Only append the next screen (UIViewcontroller), after the user finishes, but the same problem as 2) occurs.</p>
  
  <p><strong>----- edit -----</strong></p>
  
  <p>4) I can get the gestureRecognizers with <code>view.subviews.first?.gestureRecognizers</code>, but setting them <code>gestureRecognize.enabled = false</code> blocks both forward and reverse. There aren't different gestureRecognizers for each to block selectively.</p>
  
  <p>5) Intercepting the gesture and eating it when direction is forward or letting it run, with the bottom code when backward doesn't work because the user can start the swipe backward, trigger the function return and finish forward.</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      for view: UIView in pageViewController!.view.subviews {
          if (view is UIScrollView) {
              let scrollView = (view as! UIScrollView)
              self.scrollViewPanGestureRecognzier = UIPanGestureRecognizer()
              self.scrollViewPanGestureRecognzier.delegate = self
              scrollView.addGestureRecognizer(scrollViewPanGestureRecognzier)
          }
      }
  }
  
      func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -&gt; Bool {
      if gestureRecognizer == scrollViewPanGestureRecognzier {
          guard let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { return false }
          let velocity = panGestureRecognizer.velocityInView(view)
          let translation = panGestureRecognizer.translationInView(view)
          if translation.x &lt; 0 {
              return true
          }
          if velocity.x &lt; 0 {
              return true
          }
          return false
      }
      return false
  }
  </code></pre>
  
  <hr>
  
  <p>Example screen:</p>
  
  <p><a href="https://i.stack.imgur.com/RD2xqm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RD2xqm.png" alt="example"></a> <a href="https://i.stack.imgur.com/o1BGWm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o1BGWm.png" alt="enter image description here"></a></p>