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];
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];
}];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With