There's many tutorials floating around about using the new iOS 7 UIViewController transitions API and the great new interactive transition API. However, none of these seem to reference adding and removing child view controllers interactively, despite in the WWDC 2013 video on Custom UIViewController Transitions the Apple employee shows what I would imagine to be a child view controller presented with a custom transition:
(I'm assuming this as a view controller is shown on top of another one seemingly. I don't think you can transition to a new UIViewController while keeping the other visible behind it...)
Is it possible to achieve such a thing with child view controllers?
In my specific situation, I'm adding a UIPageViewController
image gallery as a child view controller but you can still see the view controller it was added to if the image the UIPageViewController
doesn't take up the full screen. I have also added the ability to slide an image off screen (akin to the iOS 7 multi-tasking close) and I'd love that to be an interactive view controller pop.
Are there any tutorials for such a thing? Is it even possible? Would this be better done with presentViewController
somehow that would allow me to view the view controller beneath?
If you watch the video again you will notice at 12:15 he references the supported presentation style
UIModalPresentationCustom
. This presentation style means that the 'from' View Controller's View is not removed from the view hierarchy, allowing you to create your own forms. So in your case you would do the following:your animation transition object would be responsible for ensuring that your page view controllers frame is not full screen. Just beware of the implications of managing two complex view controllers on screen at the same time. I would recommend rather taking a snapshot of your first view controllers view and then make it the background of the second view controllers view. The page view controller would then be a child of the second controller.
You might find this tutorial useful - http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
Better yet, someone made a go at replicating Session 218's sample on github - https://github.com/soleares/SOLPresentingFun
Happy Coding
It sounds like you want to do a custom transition with a UIViewController container. This is a tricker proposition than typical transitions because you need to provide the object that implements
UIViewControllerContextTransitioning
yourself.Despite all the required methods, this protocol is not that difficult to implement. Most of the methods are self-evident. Since you want an interactive transition you will face some hurdles I have not faced yet. Here are a few tips I recently discovered while implementing this protocol:
Don't be afraid to define your own keys for:
viewControllerForKey:
. I found that I needed a reference to the parent view controller in my animator object. The cleanest solution was defining another key to pass into this method. This works very well if the object that implements this protocol is also the parent view controller.Vend your animator by calling
animationControllerForPresentedController:presentingController:sourceController
instead of instantiating your animator yourself. Once again, this felt like a cleaner approach since it operates within the intent of the protocols. This is the method that would otherwise be called as part ofpresentViewController:animated:completion:
.Use
UIModalPresentationNone
. Since you're specifically talking about child view controllers you're not really doing a modal presentation.Add the view controller containment calls, e.g.
addChildViewController:
in your animator. This is where you'll be adding your new view controller to the view controller hierarchy.