2

I am making a custom transition for ViewController Presentation. What I have encountered is the fromViewController in the TransitionContext has the wrong type of class. It should be UICustomXXXXXViewController whereas it is shown as UINavigationController. The weird thing is that the toViewController does give back correct type.

I have a PresentationStrategy class:

class PresentationStrategy: NSObject {
    private let animator: BaseTransitioningAnimator

    init(animator: BaseTransitioningAnimator) {
        self.animator = animator
    }

    static var resultDetailBouncyExpand = PresentationStrategy(animator: BouncyExpandAnimator(duration: 0.9))

}

extension PresentationStrategy: UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController,
                             presenting: UIViewController,
                             source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        animator.transitionType = .present
        return animator
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        animator.transitionType = .dismiss
        return animator
    }
}

and in the animator's animationTransition function I simply call

let fromViewController = transitionContext.viewController(forKey: .from)!

Because I need to access something in the presenting view controller so I need to cast it to the specific class. But when It's shown to be not the type of the class that is presenting it.

Printing description of fromViewController:
<UINavigationController: 0x7fac0580e000>

And here's how I present it

presentedVC.transitioningDelegate = PresentationStrategy.resultDetailBouncyExpand
        presentingVC.present(presentedVC, animated: true)
Tony Lin
  • 922
  • 6
  • 25

0 Answers0