Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong><em>EDIT: New answer that works in any orientation.</em></strong> The original answer only works when the interface is in portrait orientation. This is b/c view transition animations that replace a view w/ a different view must occur with views at least a level below the first view added to the window (e.g. <code>window.rootViewController.view.anotherView</code>).</p> <p>I've implemented a simple container class I called <code>TransitionController</code>. You can find it at <a href="https://gist.github.com/1394947" rel="noreferrer">https://gist.github.com/1394947</a>.</p> <p>As an aside, I prefer the implementation in a separate class b/c it's easier to reuse. If you don't want that, you could simply implement the same logic directly in your app delegate eliminating the need for the <code>TransitionController</code> class. The logic you'd need would be the same however.</p> <p>Use it as follows:</p> <p><strong>In your app delegate</strong></p> <pre><code>// add a property for the TransitionController - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; MyViewController *vc = [[MyViewContoller alloc] init...]; self.transitionController = [[TransitionController alloc] initWithViewController:vc]; self.window.rootViewController = self.transitionController; [self.window makeKeyAndVisible]; return YES; } </code></pre> <p><strong>To transition to a new view controller from any view controller</strong></p> <pre><code>- (IBAction)flipToView { anotherViewController *vc = [[AnotherViewController alloc] init...]; MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate; [appDelegate.transitionController transitionToViewController:vc withOptions:UIViewAnimationOptionTransitionFlipFromRight]; } </code></pre> <p><strong><em>EDIT: Original Answer below - only works for portait orientation</em></strong></p> <p>I made the following assumptions for this example:</p> <ol> <li><p>You have a view controller assigned as the <code>rootViewController</code> of your window</p></li> <li><p>When you switch to a new view you want to replace the current viewController with the viewController owning the new view. At any time, only the current viewController is alive (e.g. alloc'ed).</p></li> </ol> <p>The code can be easily modified to work differently, the key point is the animated transition and the single view controller. Make sure you don't retain a view controller anywhere outside of assigning it to <code>window.rootViewController</code>.</p> <p><strong>Code to animate transition in app delegate</strong></p> <pre><code>- (void)transitionToViewController:(UIViewController *)viewController withTransition:(UIViewAnimationOptions)transition { [UIView transitionFromView:self.window.rootViewController.view toView:viewController.view duration:0.65f options:transition completion:^(BOOL finished){ self.window.rootViewController = viewController; }]; } </code></pre> <p><strong>Example use in a view controller</strong></p> <pre><code>- (IBAction)flipToNextView { AnotherViewController *anotherVC = [[AnotherVC alloc] init...]; MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate transitionToViewController:anotherVC withTransition:UIViewAnimationOptionTransitionFlipFromRight]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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