How to delay between two animations?

I fire one modal view controller and then immediately present another modal view controller, but currently I can’t use the animation on both of them only on the second.

Is there a way to slow down the process so that the user experiences both animations?

Below is the code below, however, the user sees only the second animation:

// 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]; 
+6
source share
4 answers

The current modular view controller has a completion block. See LINK . It is available in iOS5.0 +.

This has the advantage that you do not need to evaluate the timer delay if you want to use a timer solution.

Just put the code for your second animation in a 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]; }]; 
+9
source

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

Then in the main part of the 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 need to carefully look and see how much is needed for the first modal display, so that the animation looks good.

+1
source

You can do it in a different style.

 detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; [self presentModalViewController:detailViewController animated:YES]; [self dismissModalViewControllerAnimated:NO]; [self performSelector:@selector(someFunction) withObject:nil afterDelay:1.0]; - (void) someFunction{ //Immediately configure and show second one navController.modalPresentationStyle = UIModalPresentationFormSheet; navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:navController animated:YES]; 

}

+1
source

Try the following:

 // First one configure detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; [self presentModalViewController:detailViewController animated:YES]; //Dismiss first one [self dismissModalViewControllerAnimated:NO]; NSTimer Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(openSecondView) userInfo:nil repeats:NO]; -(void)openSecondView { //Immediately configure and show second one navController.modalPresentationStyle = UIModalPresentationFormSheet; navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:navController animated:YES]; } 

Happy coding ...

+1
source

Source: https://habr.com/ru/post/916545/


All Articles