title: How can I add a swipe gesture to my side menu controller?
body: <p>I made a side menu with some controls and I can dismiss it when the user taps outside of the side menu or if he/she selects a row inside the side menu. Now I want to add a swipe gesture to the left so that the user can dismiss it that way too.</p>
  
  <hr>
  
  <pre><code>extension MenuViewController {
  
  @objc func dismissControllerAnimated() {
      dismiss(animated: true, completion: nil)
  } }
  
  class SlideinTransition: NSObject, UIViewControllerAnimatedTransitioning {
  
  let menuViewController = MenuViewController()
  
  var isPresenting = true
  let dimmingView = UIView()
  
  func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -&gt; TimeInterval {
      return 0.5
  }
  
  func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
  
      guard let toViewController = transitionContext.viewController(forKey: .to),
      let fromViewController = transitionContext.viewController(forKey: .from) else { return }
      let containerView = transitionContext.containerView
  
      let finalWidth = toViewController.view.bounds.width * 0.3
      let finalHeight = toViewController.view.bounds.height
  
      if isPresenting{
  
          //adds a tap gesture to our dimming view
          let tapGesture = UITapGestureRecognizer(target: toViewController, action: #selector(MenuViewController.dismissControllerAnimated))
          dimmingView.addGestureRecognizer(tapGesture)
  
          //adds the dimming view
          dimmingView.backgroundColor = .black
          dimmingView.alpha = 0.0
          containerView.addSubview(dimmingView)
          dimmingView.frame = containerView.bounds
          //adds the menu view controller to our container
          containerView.addSubview(toViewController.view)
  
          //init frame off the screen
          toViewController.view.frame = CGRect(x: -finalWidth, y: 0, width: finalWidth, height: finalHeight)
      }
  
      let transform = {
          self.dimmingView.alpha = 0.5
          toViewController.view.transform = CGAffineTransform(translationX: finalWidth, y: 0)
      }
  
      //applies a specific kind of transformation to our view
      let identity = {
          self.dimmingView.alpha = 0.0
          fromViewController.view.transform = .identity
      }
  
      //animates the transition and cancels it when you click outside of the frame
      let duration = transitionDuration(using: transitionContext)
      let isCancelled = transitionContext.transitionWasCancelled
      UIView.animate(withDuration: duration, animations: {
          self.isPresenting ? transform() : identity()
      }) { (_) in
          transitionContext.completeTransition(!isCancelled)
          if !self.isPresenting {
              self.dimmingView.removeFromSuperview()
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <hr>
  
  <p>I instantiate my "MenuViewController" like this into my <strong><em>MainController</em></strong></p>
  
  <pre><code>@IBAction func didTapMenu(_ sender: UIBarButtonItem) {
      guard let menuViewController = storyboard?.instantiateViewController(withIdentifier: "MenuViewController") as? MenuViewController else { return }
      menuViewController.didTapMenuType = { menuType in
          self.transitionToNew(menuType)
      }
      menuViewController.modalPresentationStyle = .overCurrentContext
      menuViewController.transitioningDelegate = self
      present(menuViewController, animated: true)
  }
  </code></pre>
  
  <p>How can I add a <strong><em>SwipeGestureRecognizer</em></strong> to my transition? I appreciate every input. Thanks in advance!</p>