2
votes

I have UINavigationController A, which is the 'left side' view controller of a UISplitViewController and I am presenting UINavigationController B modally on UINavigationController A. This modal presentation is performed with a storyboard segue with the following properties set in Interface Builder: Kind = Present Modally, Presentation = Over Current Context, Transition = Default, Animates = true

In the root view controller of UINavigationController A, I have the following property:

let themesTransitionDelegate = ThemesTransitionDelegate()

And the following implementation of the prepareForSegue method:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.transitioningDelegate = themesTransitionDelegate
    segue.destination.view.frame = view.bounds
}

The implementation of ThemesTransitionDelegate is as follows:

class ThemesTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {

        return ThemesTransitionAnimator()
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {

        // THIS IS NEVER CALLED!
        return ThemesTransitionAnimatorDismiss()
    }

}

My custom animation works fine when presenting the modal but animationController(forDismissed dismissed: UIViewController) is never called and my custom dismissal animation is not used -- the standard modal dismissal animation is used instead.

I am using dismiss(animated: true, completion: nil) called from UINavigationController B's root view controller to trigger the dismissal of the presented modal. I have confirmed that UINavigationController B's transitioningDelegate is not nil when the dismissal is triggered.

What could be going wrong here?

1

1 Answers

2
votes

You're setting the wrong modalPresentationStyle in your storyboard. Use UIModalPresentationCustom:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {        
    segue.destination.modalPresentationStyle = .custom //Custom presentation
    segue.destination.transitioningDelegate = themesTransitionDelegate
    segue.destination.view.frame = view.bounds
}