If you don't want the animations to happen, i.e. you want user to see the root view controller after the modal view is dismissed:
CATransaction.begin()
CATransaction.setCompletionBlock {
self.dismiss(animated: true, completion: nil)
}
self.navigationController?.popViewController(animated: false)
CATransaction.commit()
Reference from: Completion block for popViewController
The above will work for popping a single view controller. If you need to pop multiple, popToRootViewController
will not work (there is an unbalanced call due to animations).
In that case, use the following (manual) method to remove them:
guard let navigationController = self.navigationController else { return }
var navigationViewControllers = navigationController.viewControllers
navigationViewControllers.removeLast(navigationViewControllers.count - 1)
self.navigationController?.viewControllers = navigationViewControllers