If you do not want the animation to occur, that is, you want the user to see the root view controller after rejecting the modal view:
CATransaction.begin() CATransaction.setCompletionBlock { self.dismiss(animated: true, completion: nil) } self.navigationController?.popViewController(animated: false) CATransaction.commit()
Help from: Completion Block for popViewController
Above will work to pop one view controller. If you need to pop out a few, popToRootViewController will not work (unbalanced call due to animation).
In this 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
source share