How To Get Index Path Cell Collection View From Ui

[Solved] How To Get Index Path Cell Collection View From Ui | Swift - Code Explorer | yomemimo.com
Question : how to get index path cell collection view from ui longpress gesture swift

Answered by : depressed-duck-478o5phfvvvr

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)") }
}

Source : https://stackoverflow.com/questions/18848725/long-press-gesture-on-uicollectionviewcell | Last Update : Wed, 20 Jan 21

Answers related to how to get index path cell collection view from ui longpress gesture swift

Code Explorer Popular Question For Swift