update:
I\'ve faced this problem again, and found another way. If presenting controller is not embedded in navigation controller, it will be hidden if p
The trivial way to attempt to achieve that is to just create the VCs you want to present modally and present one after the other. Unfortunately, this is not gonna work. What you get is just the first VC presented, all others just go nowhere. UIKit just won’t cooperate with you here.
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I found a solution: provide your own custom animation:
let transition: CATransition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionReveal
transition.subtype = kCATransitionFromBottom
self.view.window!.layer.add(transition, forKey: nil)
self.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)
This answer might seem a little unconventional, but it works. It lets you "open multiple modals", but only show one at a time. The key is to have just one modal, but use a Tab Bar Controller to switch between View Controllers.
tabBarController?.selectedIndex = 1
dismissViewControllerAnimated(true, completion: nil)
It would look something like this:
In some situations, you could have each modally presented view controller present the next one.
let window = UIApplication.sharedApplication().keyWindow!
if let modalVC = window.rootViewController?.presentedViewController {
modalVC.presentViewController(vc, animated: true, completion: nil)
} else {
window.rootViewController!.presentViewController(vc, animated: true, completion: nil)
}
Dismiss all view controllers above the presented view controller.
Apple's documentation follows:
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.
Dismiss two modal view controllers.
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#jumpTo_51
Set the correct modalPresentationStyle
on both the navigationController
AND the viewController
itself.
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
vcToPresent.modalPresentationStyle = UIModalPresentationFormSheet;
vcToPresent.preferredContentSize = CGSizeMake(650, 450);
[self presentViewController:vcToPresent animated:YES completion:^{
self.navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
}];`