DeckTransition
DeckTransition copied to clipboard
Scrolling UIDatePicker dismisses modal view controller
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?
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.
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.
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 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.
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.
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 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
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?
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