1

I have a view controller that I present in my iOS app using Swift and Xcode that is able to be dismissed by swiping down on it. I need to implement code that executes when the user swipes down on the view controller to dismiss it. I suspect there is a callback function that is called when that happens. Can anyone tell me if that's so and what the callback function is?

daniel
  • 1,446
  • 3
  • 29
  • 65

1 Answers1

0

Without too much information this is how I would set it up:

My views would be on a Navigation controller

On the view I want to dismiss with down swipe I would use a Gesture recognizer:

override func viewDidLoad() {
   super.viewDidLoad()

   let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
        swipeDown.direction = .down
   view.addGestureRecognizer(swipeDown)
}

// Handle swipe down detected
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
    // Do whatever you want before you leave

    // Pop back a view
    if let nav = navigationController {
       nav.popViewController(animated: true)
    }
}

robotos
  • 194
  • 11