0

the same question has been answered but all the recommended methods are not working for me: How to remove long gesture in UIcollectionViewCell particular cell on selection cell?

I have a table view that two gesture are added on the entire tableview, UIPanGestureRecognizer and `UITapGestureRecognizer. It made some cells not responsive as much I expected, so I want to remove both of them from some cell, is it possible? if yes, how?

Many thanks for your help in advance

Matt
  • 85
  • 1
  • 6

1 Answers1

1

Ok there is only one way to do this:

class MyViewController: UIViewController {

    @IBOutlet private var collectionView: UICollectionView!

    private let panGesture = UIPanGestureRecognizer()
    private let tapGesture = UITapGestureRecognizer()

    override func viewDidLoad() {
        super.viewDidLoad()
        panGesture.delegate = self
        tapGesture.delegate = self

        // Code to assign Gesture Recognizer
    }
}

// You should conform your controller to UIGestureRecognizerDelegate
extension MyViewController: UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        let touchLocation = touch.location(in: collectionView)
        guard let indexPath = collectionView.indexPathForItem(at: touchLocation) else {
            return true
        }
        // let's assume that you want to disable second cell (indexPath.row starts from 0)
        let disabledRow = 1
        return indexPath.row != disabledRow
    }
}

If you post your code I can help you better

iDevid
  • 507
  • 3
  • 13