Simple question, I've done a decent amount of exploration around custom navigation / transitions between UIViewController
s and am unclear about the following:
I'm looking for behavior similar to what UIPageViewController
provides (non stack-based navigation forward and backwards through "pages" of content). But I want to be able to customize the transitions, and I want the transitions to be interactive linked to a custom UIPanGestureRecognizer
.
It seems like the UIViewControllerInteractiveTransitioning
protocol provides some of what I want (interactivity, custom transitions). But because transitions are invoked solely with presentViewController:animated:
and dismissViewControllerAnimated:
it seems like it's built exclusively for use with stack-based navigation (ie UINavigationController
, UITabBarController
, modal presentation). Ie it doesn't seem like it'll play nice with something like UIPageViewController
.
If I use UIViewController
containment to build a custom container similar to UIPageViewController
(see in progress demo here) can I integrate the UIViewControllerInteractiveTransitioning
protocol into this to drive the transitions? Or do I need to roll those on my own (currently I have a rough manual implementation of interactive transitions)?
I do a lot of custom animations in my apps that most developers shy away from because I use a lot of UIViewControlloer Containment in my work.
It's the simplest way to get the transitions that you're looking for.
Here's how I would go about it:
Create a base view controller; lets call it MainViewController. It will have references to all of the other view controllers and hold the logic for the transitions. It should also follow a protocol we'll define as ViewXControllerDelegate.
Create your other view controllers; lets call them View1Controller, View2Controller, View3Controller. Add an instance of each of them as private properties of MainViewController. In the init method of MainViewController, instantiate them and add their views as subviews of MainViewController's view. Should look something like this:
self.v1c = [[View1Controller alloc]init];
[self addChildViewController:self.v1c];
[self.v1c didMoveToParentViewController:self];
//Setup each subview so that its frame makes it off screen or
//On screen depending on the app state and where you want each
//subview to animate to/from
[self.view addSubview:self.v1c.view];
....
Setup up a UIPanGestureRecognizer in each of your ViewXControllers that has its target and selector set to the parent view controller (MainViewController).
Handle all logic in your MainViewController class where you take the distance swiped, application state, the locations of each of the views into account (using helper properties in the ViewXControllers like "inactiveFrame" or "activeFrame" where the animation between them happens based on the percentage of movement that's occurred in the pan gesture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With