0

I have added Long gesture like this:

longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture))

longPress.minimumPressDuration = 0.25
collectionview.addGestureRecognizer(longPress)

How to remove long gesture?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220

3 Answers3

0

Find the cell and list of gestures added to the cell and remove the one you want ..

let cell:UICollectionViewCell =  collectioView.cellForItem(at: IndexPath(row: 5, section: 0))!


        for ges in cell.gestureRecognizers!{
            if ges is UILongPressGestureRecognizer{
               cellView.removeGestureRecognizer(ges)
            }
        }
Guna pandian
  • 83
  • 1
  • 9
0

you can remove the gesture before cell is getting ready to display.

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        if let gesture = cell.gestureRecognizers?.filter({ (gesture) -> Bool in return  gesture is UILongPressGestureRecognizer }).first {
            cell.removeGestureRecognizer(gesture)
        }
    }
Nikunj Damani
  • 753
  • 3
  • 11
0

You are adding the gesture recognizer for the whole collection view.

So, If you want only one cell not to respond for long gesture, for that particular cell disable gesture recognizers(use touchesBegan call back to check the touch event happened within the cell and if it is, handle the event by code as you wish).

If you want this functionality on multiple cells then add gesture recognizer for each cells which requires the recognizer separately.

jegadeesh
  • 875
  • 9
  • 22