how to get index path cell collection view from ui longpress gesture swift
private func setupLongGestureRecognizerOnCollection() {
let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(gestureRecognizer:)))
longPressedGesture.minimumPressDuration = 0.5
longPressedGesture.delegate = self
longPressedGesture.delaysTouchesBegan = true
collectionView?.addGestureRecognizer(longPressedGesture)
}
@objc func handleLongPress(gestureRecognizer: UILongPressGestureRecognizer) {
if (gestureRecognizer.state != .began) {
return
}
let p = gestureRecognizer.location(in: collectionView)
if let indexPath = collectionView?.indexPathForItem(at: p) {
print("Long press at item: \(indexPath.row)")
}
}
Also in Swift:
- swift test if simulator
- swift push view controller
- rotate image animated swift
- How to control the line spacing in UILabel
- array length swift
- swift initialize a view
- create alert in swift
- swift table view needs
- int in swift
- swift 5 only the day number from date
- change placeholder color swift
- how to print hello world in swift
- send email with swiftmailer symfony
- change the title of a button using Swift
- ShareSheet: UIViewControllerRepresentable swiftui
- disable swipe to delete swift
- reverse list swift
- swift collectionview scrolltoitem
- run a function only once swift
- swift ns_enum generic name
- stack view xcode
- spacing in uitextfield
- swift hide navigation bar
- how to know when text changed textfield swiftui