Is there a way to adjust time which takes for drag to begin on collection view cell? Similar to UILongPressGestureRecognizer
minimumPressDuration
property.
I know we can iterate over all gesture recognizers attached to the view and probably find the one we need. But this approach doesn't feel reliable.
Since there's no better solution, i still used 'iterate over gesture recognizers' approach.
Code is the following:
gestureRecognizers?.forEach { (recognizer) in
if let longPressRecognizer = recognizer as? UILongPressGestureRecognizer {
longPressRecognizer.minimumPressDuration = Constants.DragLongPressMinimumDuration
}
}
Constants.DragLongPressMinimumDuration
is Double
defined in Constants
struct.
Important note: do this on collection view itself (and not cells) after setting up drag and drop.
Solution works ok for iOS versions 11 and 12.
Of course this is on the edge of using private API, actual class of that recognizer is _UIDragLiftGestureRecognizer
(which is part of private API, and UILongPressGestureRecognizer
subclass). But since we're casting it to UILongPressGestureRecognizer
, technically we're not using private API.