So I built a custom presenting transition animation and everything seems to be working great except the view controller lifecycle methods are not being called on dismiss. >
I have the same problem to call viewWillAppear and other lifecycle methods.
What I did to solve it was implemented the delegate method func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?
Then to make it work I do the following:
class ViewController: UIViewController {
...
func showViewController() {
// load your view controller as you want
guard let detailViewController = loadDetailViewcontroller() as? DetailViewController else {
return }
detailViewController.modalPresentationStyle = .custom
detailViewController.transitioningDelegate = self
present(detailViewController, animated: true, completion: nil)
}
}
extension ViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return PresentationController(presentedViewController: presented, presenting: presenting)
}
}
The PresentationController is like a temporary object for the presentation. Apple's documentation
From the time a view controller is presented until the time it is dismissed, UIKit uses a presentation controller to manage various aspects of the presentation process for that view controller. The presentation controller can add its own animations on top of those provided by animator objects, it can respond to size changes, and it can manage other aspects of how the view controller is presented onscreen.