         return isInteractive ? interactiveTransition : nil
     }
 }
+
+extension ModalTransitionDelegate: UIGestureRecognizerDelegate {
+    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
+        let location = gestureRecognizer.location(in: presentedViewController?.view)
+        if location.y < 0 {
+            return true
+        } else {
+            return false
+        }
+    }
+}

    fileprivate var isInteractive: Bool = false
    fileprivate let interactiveTransition = UIPercentDrivenInteractiveTransition()
    fileprivate var presentedViewController: UIViewController?
    fileprivate var gestureRecognizer: UIPanGestureRecognizer?
    private var yVelocity: CGFloat = 0.0
    private var progress: CGFloat = 0.0
    private let velocityThreshold: CGFloat = 50.0


    private func reset() {
        isInteractive = false
        if let panGr = panGestureRecognizer {
            UIApplication.shared.keyWindow?.removeGestureRecognizer(panGr)
        }

        if let tapGr = tapGestureRecognizer {
            UIApplication.shared.keyWindow?.removeGestureRecognizer(tapGr)
        }
    }
}

extension ModalTransitionDelegate: UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        presentedViewController = presented
        return PresentModalAnimator(completion: {
            let panGr = UIPanGestureRecognizer(target: self, action: #selector(ModalTransitionDelegate.didUpdate(gr:)))
            UIApplication.shared.keyWindow?.addGestureRecognizer(panGr)
            self.panGestureRecognizer = panGr

            let tapGR = UITapGestureRecognizer(target: self, action: #selector(ModalTransitionDelegate.didTap(gr:)))
            UIApplication.shared.keyWindow?.addGestureRecognizer(tapGR)
            self.tapGestureRecognizer = tapGR
        })
    }

