title: [Big help]Custom transition animation not triggered when VC present
body: <p>:)</p>
  
  <p>I want make some change to source code for 17-custom-presentation-controller to make custom transition animation,all my change is in class PopAnimator.</p>
  
  <p>all my code is in here : <a href="https://github.com/hopy11/TransitionTest" rel="nofollow noreferrer">https://github.com/hopy11/TransitionTest</a></p>
  
  <p>This is my changes:</p>
  
  <p>add a new instance variable in PopAnimator to save transitionContext:</p>
  
  <p>var ctx:UIViewControllerContextTransitioning!</p>
  
  <p>I rewrite the method:</p>
  
  <p>animateTransition(using transitionContext: UIViewControllerContextTransitioning)</p>
  
  <p>to this :</p>
  
  <pre><code>func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
      let containerView = transitionContext.containerView
      let toView = transitionContext.view(forKey: .to)!
  
      //save transitionContext
      ctx = transitionContext
  
      containerView.addSubview(toView)
  
      let animation = CATransition()
      animation.duration = duration / 2
  
      animation.type = "cube"
      //use type kCATransitionReveal is not work too ...
      //animation.type = kCATransitionReveal
  
      animation.subtype = kCATransitionFromLeft
      animation.delegate = self
  
      containerView.layer.add(animation, forKey: nil)
  }
  </code></pre>
  
  <p>3.Last I make class PopAnimator confirm CAAnimationDelegate delegate, and add the new method:</p>
  
  <pre><code>func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
      if ctx != nil{
          //make transition complete
          ctx.completeTransition(true)
          dismissCompletion?()
      }
  }
  </code></pre>
  
  <p>When run the App,the transition animation is look good when detailsVC dismiss,but nothing happened when presenting detailsVC!</p>
  
  <p><a href="https://i.stack.imgur.com/9VkTc.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9VkTc.gif" alt="demo"></a></p>
  
  <p>You can see the demo above : when user tap the bottom left green view,it present detailsVC,but no animation happened!!! but when dismiss detailsVC,the animation work fine!</p>
  
  <p>What’s wrong with it???
  and how to fix it???</p>
  
  <p>all my code is in here : <a href="https://github.com/hopy11/TransitionTest" rel="nofollow noreferrer">https://github.com/hopy11/TransitionTest</a></p>
  
  <p>thanks a lot! :)</p>