Disable gesture to pull down form/page sheet modal presentation

前端 未结 14 2819
我寻月下人不归
我寻月下人不归 2020-11-27 13:58

In iOS 13 modal presentations using the form and page sheet style can be dismissed with a pan down gesture. This is problematic in one of my form sheets because the user dra

14条回答
  •  遥遥无期
    2020-11-27 14:31

    In my case, I have a modal screen with a view that receives touches to capture customer signatures.

    Disabling the gesture recognizer in the navigation controller solved the problem, preventing the modal interactive dismissal from being triggered at all.

    The following methods are implemented in our modal view controller, and are called via delegate from our custom signature view.

    Called from touchesBegan:

    private func disableDismissalRecognizers() {
        navigationController?.presentationController?.presentedView?.gestureRecognizers?.forEach {
            $0.isEnabled = false
        }
    }
    

    Called from touchesEnded:

    private func enableDismissalRecognizers() {
        navigationController?.presentationController?.presentedView?.gestureRecognizers?.forEach {
            $0.isEnabled = true
        }
    }
    

    Here is a GIF showing the behavior:

    This question, flagged as duplicate, describes better the issue I had: Disabling interactive dismissal of presented view controller on iOS 13 when dragging from the main view

提交回复
热议问题