I am looking to build an app that has 6 view controllers laid out in a cube structure (instead of having a tab bar for navigation…). I used this example to make the cube transitions: switch two view controller's view in a cube animation
However, most of the examples (another one: how does the CATransition work?) show how to transition between UIViews rather than UIViewControllers, which is what I am interested in.
My questions are: how do I use CATransition to transition between UIViewControllers, and also – how do I go back from one UIViewController to another assuming that I am using the pushViewController: method (so far I have been using presentModalViewController: and get back (say, for cancel) used this method dismissModalViewControllerAnimated:).
Thanks.
You cannot use CATransition to switch between two view controllers, but you can simply use the view controller’s view and switch it with another view controller’s view.
iOS 5 made transitioning with UIViewControllers easier as it introduces the
transitionFromViewController:toViewController:duration:options:animations:completion:method.In the end, you’ll still be using the UIViews of the UIViewControllers.
(Actually, the link you provided is exactly how you transition between two UIViewControllers. Remember, view controllers only manage views and aren’t really views themselves. Switching back won’t be as easy as dismissModalViewControllerAnimated: but sometimes customization isn’t easy).
Here’s an example with using the iOS 5 method:
UIViewController *controller = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[controller.view setBackgroundColor:[UIColor greenColor]];
Note, you’ll have to do the following beforehand.
There are a few things you have to do before using these methods. The main difference is that you’re going to have one more view controller than you current have. This extra UIViewController serves as a container for the other two (kind of like how currently, self.view is a container for the two UIViews you have).