DeckTransition icon indicating copy to clipboard operation
DeckTransition copied to clipboard

Scrolling UIDatePicker dismisses modal view controller

Open eddielee6 opened this issue 7 years ago • 10 comments

The modal view I am displaying using DeckTransition contains a UIDatePicker, when the date picker is swiped to select a date/time this triggers the dismiss gesture. I have reproduced this using the Example project just by adding a UIDateView to the view.

Is there a work around to resolve this issue?

eddielee6 avatar Jan 05 '18 23:01 eddielee6

Thanks for filling an issue.

This is a problem with any views that do their own touch handling. I'm still trying to search for solutions, but unfortunately I haven't been able to find one yet.

In the meantime all I can recommend is to disable swipe-to-dismiss.

HarshilShah avatar Jan 25 '18 08:01 HarshilShah

Thanks, hopefully there is a real fix soon. For the time being I have fixed this by positioning a UIScrollView behind the UIDatePicker with a large contentSize and a contentOffset set to the centre.

This seems to trick the DeckTransition into not listening for scroll events on this view.

eddielee6 avatar Jan 26 '18 20:01 eddielee6

I have the same problem with reordering UITableViewCells in the modal view. It would be helpful to enable/disable swipeToDismiss as needed. Is that feasible?

gorkemg avatar Feb 11 '18 00:02 gorkemg

@gorkemg That's my fallback in case I can't find a better solution. But I'd much rather have it be either declarative or requiring no API change on the user's end if that's doable at all.

HarshilShah avatar Feb 14 '18 12:02 HarshilShah

I agree with @gorkemg - I have a collection view which is swiping horizontally. That triggers the 'swipe to dismiss' gesture causing the whole VC to move with every little vertical movement.

cyrilzakka avatar Mar 15 '18 13:03 cyrilzakka

Concerning the previous point I raised, I modified the following function in DeckPresentationController to fix it. No adverse effects so far.

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return false
}

cyrilzakka avatar Mar 15 '18 13:03 cyrilzakka

@cyrilzakka That breaks swipe to dismiss if you’re not at the exact top of the scroll view when you begin the dismiss gesture

Sent with GitHawk

HarshilShah avatar Mar 15 '18 14:03 HarshilShah

Oh I guess I'll look into it a bit more. What would you suggest I do for horizontal scrolls? I might modify shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) with something along the lines of:

if abs(gestureRecognizer.translation.x) > abs(gestureRecognizer.translation.y) then return false. Thoughts?

cyrilzakka avatar Mar 15 '18 14:03 cyrilzakka

Would’ve implemented it already if I had an exact solution about what to do!

Sent with GitHawk

HarshilShah avatar Mar 15 '18 15:03 HarshilShah

For anyone interested: you can also avoid running into this issue by placing an UITextField in your interface. All you have to do in code is to set the .inputView attribute to a Date Picker (or a Picker View).

Tapping the UITextField will trigger the keyboard launching, which is now set to a Picker View that may be scrolled without any problems.

Here is a sample code. I've tested this workaround with iOS 12 and XCode 10.

@IBOutlet var sampleTextField: UITextField!
let picker = UIDatePicker()
picker.datePickerMode = .dateAndTime
picker.minimumDate = Date()
picker.addTarget(self, action: #selector(self.dateChanged(datePicker:)), for: .valueChanged)

sampleTextField.inputView = picker

gabrieldluca avatar Nov 28 '18 02:11 gabrieldluca