iOS documentation for dismissViewControllerAnimated:completion:
states:
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
This means when dismissing two modal view controllers at once using
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
the animation shown should be the top modal view being dismissed.
This is indeed the case in iOS 7 and prior, but in iOS 8 the animation shown is not the top-most view (in my experience, it's the second top-most view). Is this behavior a bug in iOS 8 or am I doing something wrong?
As commented above: I see the exact same issue in an unwind segue context. I just toke the workaround as described here using a screenshot and add it as a subview to all intermediate viewControllers: How to dismiss a stack of modal view controllers with animation without flashing on screen any of the presented VCs between the top and bottom?
// this in during unwind in a custom UIStoryboardSegue (that is the reason why it might look wrong with what is what: srcViewController and destViewController
UIViewController* aPresentedViewController = destViewController.presentedViewController;
while (aPresentedViewController != nil) {
if (aPresentedViewController == srcViewController) {
break;
}
UIView *anotherSrcViewCopy = [srcViewController.view snapshotViewAfterScreenUpdates: NO];
anotherSrcViewCopy.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[aPresentedViewController.view addSubview:anotherSrcViewCopy];
// recurse through the presentedViewController hierarchy
aPresentedViewController = aPresentedViewController.presentedViewController;
}
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