Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:00:18+00:00 2026-05-27T03:00:18+00:00

NavigationControllers have ViewController stacks to manage, and limited animation transitions. Adding a view controller

  • 0

NavigationControllers have ViewController stacks to manage, and limited animation transitions.

Adding a view controller as a sub-view to an existing view controller requires passing events to the sub-view controller, which is a pain to manage, loaded with little annoyances and in general feels like a bad hack when implementing (Apple also recommends against doing this).

Presenting a modal view controller again places a view controller on top of another, and while it doesn’t have the event passing problems described above, it doesn’t really ‘swap’ the view controller, it stacks it.

Storyboards are limited to iOS 5, and are almost ideal, but cannot be used in all projects.

Can someone present a SOLID CODE EXAMPLE on a way to change view controllers without the above limitations and allows for animated transitions between them?

A close example, but no animation:
How to use multiple iOS custom view controllers without a navigation controller

Edit: Nav Controller use is fine, but there needs to be animated transition styles (not simply the slide effects) the view controller being shown needs to be swapped completely (not stacked). If the second view controller must remove another view controller from the stack, then it’s not encapsulated enough.

Edit 2: iOS 4 should be the base OS for this question, I should have clarified that when mentioning storyboards (above).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:00:18+00:00Added an answer on May 27, 2026 at 3:00 am

    EDIT: New answer that works in any orientation.
    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. window.rootViewController.view.anotherView).

    I’ve implemented a simple container class I called TransitionController. You can find it at https://gist.github.com/1394947.

    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 TransitionController class. The logic you’d need would be the same however.

    Use it as follows:

    In your app delegate

    // 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;
    }
    

    To transition to a new view controller from any view controller

    - (IBAction)flipToView
    {
        anotherViewController *vc = [[AnotherViewController alloc] init...];
        MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
        [appDelegate.transitionController transitionToViewController:vc withOptions:UIViewAnimationOptionTransitionFlipFromRight];
    }
    

    EDIT: Original Answer below – only works for portait orientation

    I made the following assumptions for this example:

    1. You have a view controller assigned as the rootViewController of your window

    2. 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).

    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 window.rootViewController.

    Code to animate transition in app delegate

    - (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;
                        }];
    }
    

    Example use in a view controller

    - (IBAction)flipToNextView
    {
        AnotherViewController *anotherVC = [[AnotherVC alloc] init...];
        MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
        [appDelegate transitionToViewController:anotherVC
                                 withTransition:UIViewAnimationOptionTransitionFlipFromRight];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation
Let's say you have a tab view controller on the navigation controller view stack.
I have several viewControllers controlled by a navigation controller. For example, viewController A and
I have standard view controller acting as the delegate for a modal view controller
I have a view controller that i'm trying to push onto the navigation stack.
Hey all... I have a view controller (A) which on some action, alloc init's
If I have a stack of views controlled by a view controller, and a
I have a tabbed application with navigation controllers in tabs and view controller in
I have a custom view controller showing the details of the selected item in
I have a view controller which contains a table view, and which is wrapped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.