Is it possible to Push/Present a ViewController on Swipe Down?

This is my swipe gesture recognizer. It's working so far, but whenever I try to push a View Controller on Swipe Down it would run the code block and I would get the print in the console. But won't push any view controller.

Also, it doesn't return o throw any error or warning. So not sure how to go about this:

Expected behavior: On swipe down, push UIAlertController

Code Block class GestureManager: NSObject, TVDocumentViewControllerDelegate {
  var appDelegate = UIApplication.shared.delegate as! AppDelegate
  var vc: UIViewController?
   
  init(vc: UIViewController) {
    self.vc = vc
     
    let swipeRight = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeRight.direction = .right
    let swipeLeft = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeLeft.direction = .left
    let swipeUp = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeUp.direction = .up
    let swipeDown = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeDown.direction = .down
     
    vc.view.addGestureRecognizer(swipeRight)
    vc.view.addGestureRecognizer(swipeLeft)
    vc.view.addGestureRecognizer(swipeUp)
    vc.view.addGestureRecognizer(swipeDown)
  }
  @objc func respondToSwipeGesture(_ gesture : UIGestureRecognizer) {
    if let swipeGesture = gesture as? UISwipeGestureRecognizer {
      switch swipeGesture.direction {
      case .right:
        print("swiped right!")
      case .left:
        print("Swiped left")
      case .up:
        print("Swiped up")
      case .down:
        print("Swiped down")
        let alertController = UIAlertController(title: "Test", message: "Test message", preferredStyle: .alert )
        appDelegate.appController?.navigationController.pushViewController(alertController, animated: true)
      default:
        return
      }
    }
  }
}


Could you show the full class declaration, including the initial lines ?
If you are in a navigation stack, swipe down is used to dismiss the present view.
You can't use it.

In IB: if you replace in the vc the segue kind from 'Present as popover' to 'Present Modally' or 'Show (push)', that should work.

Your code raises several questions:
  • Why do you need the appDelegate ?

  • where do you use this int(vc: UIViewController)

Message: could you close the other threads you have opened if answer is correct ?
Is it possible to Push/Present a ViewController on Swipe Down?
 
 
Q