Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling UIDatePicker dismisses modal view controller #58

Open
eddielee6 opened this issue Jan 5, 2018 · 10 comments
Open

Scrolling UIDatePicker dismisses modal view controller #58

eddielee6 opened this issue Jan 5, 2018 · 10 comments

Comments

@eddielee6
Copy link

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?

@HarshilShah
Copy link
Owner

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.

@eddielee6
Copy link
Author

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.

@gorkemg
Copy link

gorkemg commented Feb 11, 2018

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?

@HarshilShah
Copy link
Owner

@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.

@cyrilzakka
Copy link

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
Copy link

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
}

@HarshilShah
Copy link
Owner

@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

@cyrilzakka
Copy link

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?

@HarshilShah
Copy link
Owner

HarshilShah commented Mar 15, 2018

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

Sent with GitHawk

@gabrieldluca
Copy link

gabrieldluca commented Nov 28, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants