     /// 自定义弹出和消失的转场动画
     func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
         
+        isPresent = true
+        
+        return self
+    }
+    
+    /// 自定义消失的转场动画
+    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
+        
+        
+        isPresent = false
         return self
     }
     




extension HomeViewController : UIViewControllerAnimatedTransitioning{
    
    
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval{
       
        return 2.0
    }
    
    /// 获取“转场动画上下文”，可以通过上下文获取弹出的View额消失的view

    // .from 消失的动画
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning){
        
        isPresent ? animateForPresent(transitionContext: transitionContext) : animateForDismiss(transitionContext: transitionContext)
  
    }
    
    
    /// 自定义弹出动画
    func animateForPresent(transitionContext: UIViewControllerContextTransitioning) {
        
        // 得到要去的view
        let presentView = transitionContext.view(forKey: .to)
        
        // 添加到Model的ContainerView中去
        transitionContext.containerView.addSubview(presentView!)
        
        // 执行对应动画
        presentView?.transform = CGAffineTransform(scaleX: 1.0, y: 0.0)
        presentView?.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
        
        UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: { () -> Void in
            presentView?.transform = CGAffineTransform.identity
        }, completion: { (_) -> Void in
            // 必须告诉转场上下文你已经完成动画
            transitionContext.completeTransition(true)
        })
    }
    
    
    /// 自定义弹出动画
    func animateForDismiss(transitionContext: UIViewControllerContextTransitioning) {
        
        // 得到要去的view
        let presentView = transitionContext.view(forKey: .from)
        
        // 添加到Model的ContainerView中去
        transitionContext.containerView.addSubview(presentView!)
        
        // 执行对应动画
        UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: { () -> Void in
            
            presentView?.transform = CGAffineTransform(scaleX: 1.0, y: 0.0001)

        }, completion: { (_) -> Void in
            
            // 移除View并告诉上下文已经完成动画
            presentView?.removeFromSuperview()
            transitionContext.completeTransition(true)
        })
    }
    
    
