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. >
@John Tracids' anser solved my issue. Thanks John!
But I would like to extend an answer a bit.
If you are presenting UIViewController instance with modalPresentationStyle = .custom
(objc UIModalPresentationCustom) in order to keep viewcontroller's lifecycle methods being called, you have to manage viewcontroller’s appearance explicitly. To do that just call beginAppearanceTransition before animation and endAppearanceTransition at the animation completion block.
Also you can pass to your transitioning animator class custom UIPresentationController subclass with overridden value shouldRemovePresentersView
returning true
without calling beginAppearanceTransition
// Swift 4
put this to your custom UIViewControllerAnimatedTransitioning class before animation
fromViewController.beginAppearanceTransition(false, animated: true)
toViewController.beginAppearanceTransition(true, animated: true)
UIView.animate(withDuration: animationDuration, animations: {
// animation logic…
}) { finished in
fromViewController.endAppearanceTransition()
toViewController.endAppearanceTransition()
let transitionSuccess = !transitionContext.transitionWasCancelled
transitionContext.completeTransition(transitionSuccess)
}
// UIPresentationController subclass
class PresentationController: UIPresentationController {
override var shouldRemovePresentersView: Bool { return true }
}