2

I'm implementing a custom UIPageViewController so that I can use custom animations between view controllers.

I can transition from one view controller to the other with the transition(from:to:duration:options:animations:completion:) method. However I want the transition to be interactive, controlled by a pan gesture recognizer.

I implemented both

animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController)

and

interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning)

on the child view controllers but these methods are not called when using the above transition function.

How can I get an interactive transition between two child view controllers?

Morpheus
  • 1,189
  • 2
  • 11
  • 33
  • `UIPageViewController` transition is interactive on it's own. – nayem Oct 26 '18 at 09:16
  • And did you conform to `UIViewControllerTransitioningDelegate` protocol? Did you set the `transitioningDelegate` property of your `UI(Page)ViewController`? – nayem Oct 26 '18 at 09:22
  • My container is not actually a UIPageViewController, it's just a UIViewController imitating a pageviewcontroller. Setting the transitioningDelegate of the container does not affect the transition between child view controllers — I tried it. – Morpheus Oct 26 '18 at 09:36

1 Answers1

1

A bit late, but since there is no reply. I have implemented an example of an interactive and interruptible transition between two child view controllers in a custom container view controller. github repo

The key to achieving it, is to use UIViewPropertyAnimator. A word of caution though, my example creates a class that conforms to UIViewControllerContextTransitioning. Apple says we shouldn’t create classes that conforms to that protocol, nor should we create objects that conforms to it. However, my example works, and may give you ideas on how to solve your own problem.

joqqy
  • 408
  • 4
  • 11