Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay between 2 animations?

I am dismissing one modal view controller and then immediately presenting another modal view controller however I cannot currently use animation on both of them only the second one.

Is there anyway to delay the process so that the user experiences both animations?

The code below currently works however user only sees the second animation obviously:

// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES];

//Dismiss first one
[self dismissModalViewControllerAnimated:NO]; 

//Immediately configure and show second one
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
like image 840
TheLearner Avatar asked May 24 '12 10:05

TheLearner


2 Answers

There is now a completetion block available in present modal view controller. See this LINK. This is available in iOS5.0 +.

This has the advantage that you don't need to estimate the timer delay if you were to use a timer solution.

Just put the code for your second animation in the block:

//Block safe reference to self to prevent retain cycles
__block typeof (self) selfReference = self;

// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES completion:
^{
    //Dismiss first one
    [selfReference dismissModalViewControllerAnimated:NO]; 

    //Immediately configure and show second one
    navController.modalPresentationStyle = UIModalPresentationFormSheet;
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [selfReference presentModalViewController:navController animated:YES];
 }];
like image 146
James Webster Avatar answered Nov 15 '22 08:11

James Webster


Make a selector that does the following:

- (void)showSecondModalVC {
  //Dismiss first one
  [self dismissModalViewControllerAnimated:NO]; 

  //Immediately configure and show second one
  navController.modalPresentationStyle = UIModalPresentationFormSheet;
  navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentModalViewController:navController animated:YES];
}

An then in the main piece of code:

// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES];

[self performSelector:@selector(showSecondModalVC) 
         withObject:nil 
         afterDelay:0.5f];

You will have to look closely and see how much it takes for the first modal to show so the animations look good.

like image 44
Fran Sevillano Avatar answered Nov 15 '22 06:11

Fran Sevillano