1
votes

I have a view that is presented modally. This comes with the iOS 13/14 swipe down to dismiss feature.

When the user has started to dismiss the modal view, I get this delegate call:

func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {

}

This gets called as soon as the user has started to drag the view down. However, it can get cancelled.

Following call gives me once the view has done dismissing:

func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {


}

What I need is to know when the user has finished the gesture to dismiss and the view will be finishing the dismissal.

I was able to take it few steps forward, but still missing the above-required detection:

func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
        
        //User started dismissing, with no guarantee

        self.transitionCoordinator!.animate(alongsideTransition: {(context: UIViewControllerTransitionCoordinatorContext) -> Void in
            
            //Dismissal is animating. Could be finishing or canceling the dismissal

            
        }, completion: {(  context: UIViewControllerTransitionCoordinatorContext) -> Void in
            if context.isCancelled {
                //Dismissal got cancelled
            } else {
                //Dismissal has completed. Too Late!
            }
        })

        
        
    }
1
Yeah, I see what you mean: you want the moment the user lets go and the runtime says, "that's a completion not a cancellation". Is this because you've got your own animation to do?matt
Exactly. Not animation. A task that has multiple queues and complex. I cannot do it as the initial detection, since the user can drag and let it go and repeat, which would crash.Gizmodo
Hmm, you might want to change that idea about coordinating the task with the dismissal. It sounds kind of skanky that you have to worry about the dismissal with such precision. Anyway, the furthest I've ever gotten on this is exactly what you already have: use willDismiss and grab the transition coordinator. So that may be the best you can do. Short of throwing out the baby with the bath water and turning this into a full screen presentation, of course.matt
ViewWillDisappear came close. It gets called at the beginning of panning.Gizmodo

1 Answers

0
votes
    final func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
            
            self.transitionCoordinator?.notifyWhenInteractionChanges({ (context) in
                if context.isCancelled {
                    print ("will cancel")
                } else {
                    print ("will finish")
    
                }
            })
}