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 6925473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:47:38+00:00 2026-05-27T10:47:38+00:00

I can’t seem to find a good example on how to use transitionFromViewController:toViewController:duration:options:animations:completion: properly.

  • 0

I can’t seem to find a good example on how to use transitionFromViewController:toViewController:duration:options:animations:completion: properly.

Is this correct? (assuming I want to swap a VC with another)

// Assume fromVC and toVC view controllers are defined and fromVC is already added as a child view controller
[self addChildViewController:toVC];

[self transitionFromViewController:fromVC toViewController:toVC duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:NULL completion:^(BOOL finished) {
    [fromVC willMoveToParentViewController:nil];
    [fromVC removeFromParentViewController];
    [toVC didMoveToParentViewController:self];
}];

The documentation isn’t that clear about when to call what:

The addChildViewController: method calls the
willMoveToParentViewController: method of the view controller to be
added as a child before adding it, but it does not call the
didMoveToParentViewController: method. The container view controller
class must call the didMoveToParentViewController: of the child view
controller after the transition to the new child is complete or, if
there is no transition, immediately after calling the
addChildViewController: method.

Likewise, it is is the responsibility of the container view controller
to call the willMoveToParentViewController: method before calling the
removeFromParentViewController: method. The
removeFromParentViewController: method calls the
didMoveToParentViewController: method of the child view controller.

Another thing is, how do you use the animations block in this case? Notice in the above code I just put NULL. (I am familiar with block per se, I am just not sure what to put exactly in this one)

  • 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-27T10:47:39+00:00Added an answer on May 27, 2026 at 10:47 am

    I’ve implemented this sort of thing similarly in the past. But, I would move -willMoveToParentViewController: outside the completion block since that view controller should be notified before it gets moved (i.e., by the time the completion block has run, fromVC has already had its parent VC set to nil. So all in all, something like this:

    [self addChildViewController:toVC];
    [fromVC willMoveToParentViewController:nil];
    
    [self transitionFromViewController:fromVC toViewController:toVC duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{} completion:^(BOOL finished) {
        [fromVC removeFromParentViewController];
        [toVC didMoveToParentViewController:self];
    }];
    

    In terms of animations, you should never set this parameter to NULL, according to the method documentation. If you have no view properties you want to animate, then you can simply pass it an empty block ^{}. Basically this parameter is used for animating properties of your views in your view hierarchy during the transition. The list of animatable properties can be found in the UIView documentation under the “Animations” heading. As an example, say you don’t want your whole view handled by fromVC to cross dissolve, but only want one subview in its view hierarchy named subview1 to fade out. You can do this using the animations block:

    [self addChildViewController:toVC];
    [fromVC willMoveToParentViewController:nil];
    
    [self transitionFromViewController:fromVC 
                      toViewController:toVC
                              duration:0.3
                               options:UIViewAnimationOptionTransitionNone
                            animations:^{
                                           [subview1 setAlpha:0.0];
                                       }
                            completion:^(BOOL finished) {
                                           [fromVC removeFromParentViewController];
                                           [toVC didMoveToParentViewController:self];
                                       }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can I get a 'when to use' for these and others? <% %> <%#
Can anyone recommend a good library for generating an audio file, such as mp3,
Can you suggest some good MVC framework for perl -- one I am aware
Can anyone give me an example of how to return the following json simply
Can I run this in a Windows command prompt like I can run it
Can anybody help me? What should be the datatype for this type -07:00:00 of
Can someone guide me on a possible solution? I don't want to use /bin/cp

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.