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?
            Asked
            
        
        
            Active
            
        
            Viewed 850 times
        
    1
            
            
        - 
                    2Does this help? https://stackoverflow.com/questions/56568967/detecting-sheet-was-dismissed-on-ios-13/56569048#56569048 – rbaldwin May 13 '20 at 19:49
- 
                    Yes. I think that's what I need. Thank you very much. – daniel May 13 '20 at 19:51
1 Answers
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
