HarshilShah / DeckTransition

A library to recreate the iOS Apple Music now playing transition
MIT License
2.19k stars 168 forks source link

Scrolling UIDatePicker dismisses modal view controller #58

Open eddielee6 opened 6 years ago

eddielee6 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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

Sent with GitHawk

gabrieldluca commented 5 years ago

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