Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use Apple's new viewController containment system. For more in-depth information check out the WWDC 2011 session video "Implementing <code>UIViewController</code> Containment".</p> <p>New to iOS5, <code>UIViewController</code> Containment allows you to have a parent viewController and a number of child viewControllers that are contained within it. This is how the UISplitViewController works. Doing this you can stack view controllers in a parent, but for your particular application you are just using the parent to manage the transition from one visible viewController to another. This is the Apple approved way of doing things and animating from one child viewController is painless. Plus you get to use all the various different <code>UIViewAnimationOption</code> transitions!</p> <p>Also, with UIViewContainment, you do not have to worry, unless you want to, about the messiness of managing the child viewControllers during orientation events. You can simply use the following to make sure your parentViewController forwards rotation events to the child viewControllers.</p> <pre><code>- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers{ return YES; } </code></pre> <p>You can do the following or similar in your parent's viewDidLoad method to setup the first childViewController:</p> <pre><code>[self addChildViewController:self.currentViewController]; [self.view addSubview:self.currentViewController.view]; [self.currentViewController didMoveToParentViewController:self]; [self.currentViewController.swapViewControllerButton setTitle:@"Swap" forState:UIControlStateNormal]; </code></pre> <p>then when you need to change the child viewController, you call something along the lines of the following within the parent viewController:</p> <pre><code>-(void)swapViewControllers:(childViewController *)addChildViewController:aNewViewController{ [self addChildViewController:aNewViewController]; __weak __block ViewController *weakSelf=self; [self transitionFromViewController:self.currentViewController toViewController:aNewViewController duration:1.0 options:UIViewAnimationOptionTransitionCurlUp animations:nil completion:^(BOOL finished) { [aNewViewController didMoveToParentViewController:weakSelf]; [weakSelf.currentViewController willMoveToParentViewController:nil]; [weakSelf.currentViewController removeFromParentViewController]; weakSelf.currentViewController=[aNewViewController autorelease]; }]; } </code></pre> <p>I posted a full example project here: <a href="https://github.com/toolmanGitHub/stackedViewControllers" rel="nofollow noreferrer">https://github.com/toolmanGitHub/stackedViewControllers</a>. This <a href="https://github.com/toolmanGitHub/BDApplicationHelpers" rel="nofollow noreferrer">other project</a> shows how to use <code>UIViewController</code> Containment on some various input viewController types that do not take up the whole screen. Good luck</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload