Last active
October 26, 2020 10:40
-
-
Save pstasiak/521f8959c6831a6cde537cc25e4e9685 to your computer and use it in GitHub Desktop.
Setting custom drag gesture initiation time. Important: Should be called after each update of `dragDelegate`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UICollectionView { | |
func setupDragInitiationTime(_ time: TimeInterval) { | |
let dragInitiatingRecognizerName = "dragInitiation" | |
let longPressRecognizers = gestureRecognizers?.compactMap { | |
$0 as? UILongPressGestureRecognizer | |
} ?? [] | |
let dragInitiatingRecognizers = longPressRecognizers.filter { | |
$0.name == dragInitiatingRecognizerName | |
} | |
assert( | |
!dragInitiatingRecognizers.isEmpty, | |
""" | |
Unable to setup drag initiation time - no gesture recognizer named "\(dragInitiatingRecognizerName)". | |
Existing UILongPressGestureRecognizer subclasses: | |
\(longPressRecognizers) | |
""" | |
) | |
dragInitiatingRecognizers.forEach { $0.minimumPressDuration = time } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment