Collection view drag and drop delay

风格不统一 提交于 2019-12-08 06:30:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53561281/collection-view-drag-and-drop-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!