Morpheus
Morpheus

Reputation: 1289

Interactive transition between two child view controllers

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?

Upvotes: 2

Views: 825

Answers (1)

joqqy
joqqy

Reputation: 410

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.

Upvotes: 1

Related Questions