I have a long View Controllers hierarchy;
in the first View Controller I use this code:
SecondViewController *svc = [[SecondViewController alloc] i
Swift 3 extension based upon the above answers.
Principle for a stack like that : A -> B -> C -> D
On completion, dismiss from A with animation
extension UIViewController {
func dismissModalStack(animated: Bool, completion: (() -> Void)?) {
let fullscreenSnapshot = UIApplication.shared.delegate?.window??.snapshotView(afterScreenUpdates: false)
if !isBeingDismissed {
var rootVc = presentingViewController
while rootVc?.presentingViewController != nil {
rootVc = rootVc?.presentingViewController
}
let secondToLastVc = rootVc?.presentedViewController
if fullscreenSnapshot != nil {
secondToLastVc?.view.addSubview(fullscreenSnapshot!)
}
secondToLastVc?.dismiss(animated: false, completion: {
rootVc?.dismiss(animated: true, completion: completion)
})
}
}
}
A little flickering on simulator but not on device.