6

TLDR: Looking for a solution to enable interactive dismissal when dragging down from the navigation bar, but not from the view controller's view.

Introduction

iOS 13 modal view controllers allow for disabling the interactive dismissal in a few ways:

  1. Setting vc.modalPresentationStyle = .fullScreen (see Presenting modal in iOS 13 fullscreen)
  2. Setting viewController.isModalInPresentation = true (see Disable the interactive dismissal of presented view controller in iOS 13)
  3. Implementing UIAdaptivePresentationControllerDelegate delegate methods (see UINavigationBar changes in iOS13)

The first one is great if you want same behavior as iOS 12 and below.

The second one, is great to prevent interactive dismissal, but still allows for dragging the view controller down when pulling from the main view controller view (with a nice animation).

The later allows for better handling of events, but doesn't help preventing dragging from the view controller's view.

Pull-to-refresh (close)

The closest thing I've seen is setting the refresh control to prevent dismissal during pull-to-refresh. This GIF shows the behavior I'm looking for (source):

interactive-dismissal-pull-to-refresh

This pull-to-refresh interaction can be seen in the modal Inbox screen on the iOS Calendar app.

What I'm looking for

The behavior I'm looking for is the same as pull-to-refresh above, but without the scroll view and refresh control.

Basically, touches on the view controller's view should not trigger the interactive dismissal.

I've tried the following, with no luck:

  • view.isExclusiveTouch = true
  • view.isUserInteractionEnabled = false

In summary, what I need:

  1. Interactive dismissal enabled when dragging from the navigation bar
  2. Interactive dismissal disabled when dragging anywhere inside the main view
  3. No bounce for dismissal

Thank you!

Eneko Alonso
  • 18,884
  • 9
  • 62
  • 84
  • 1
    Please read the entire question before marking as duplicate! – Eneko Alonso Oct 31 '19 at 16:08
  • Sorry, I add the wrong duplicate. Fixed now. – rmaddy Oct 31 '19 at 16:09
  • Thank you, @maddy – Eneko Alonso Oct 31 '19 at 17:56
  • @EnekoAlonso did you find a way to solve this? I'm stuck with the exact same problem! – Andres Dec 20 '19 at 10:31
  • @Andres, yes, the duplicate link mentioned disabling gesture recognizers in the modal ViewController's view. https://stackoverflow.com/questions/56718552/disable-gesture-to-pull-down-form-page-sheet-modal-presentation – Eneko Alonso Dec 23 '19 at 23:45
  • Posted my solution here: https://stackoverflow.com/a/59462475/422288 – Eneko Alonso Dec 24 '19 at 00:03
  • @EnekoAlonso thanks for sharing and posting it! I’ve been spending a lot of time on this and found that this solution doesn’t work when having a table view because the pan gesture to scroll the tableview somehow “forwards” the event to the dismiss behavior. If I turn off the pan gesture of the table I can’t scroll it anymore... – Andres Dec 24 '19 at 08:28

0 Answers0