Reputation: 1473
I have created a double tap gesture for my Collection View. When a cell in the Collection View is double tapped i disable user interaction to the cell. This stops me being able to single tap that cell while a process runs. However i can still double tap that cell which runs the process again. I still want double tap to be available for other cells in the collection, i just want to disable it for the cell that is running process. When the process is finished user interaction is turned back on, and hopefully double tap also.
So this is how i define double tap, in viewDidLoad of the View Controller holding the Collection View:
// add gesture recogniser
let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didDoubleTap))
doubleTap.numberOfTapsRequired = 2
doubleTap.delaysTouchesBegan = true
self.collectionView.addGestureRecognizer(doubleTap)
And I'm just switching userInteraction as usual when needed depending on state of process.
cell.isUserInteractionEnabled = false
cell.isUserInteractionEnabled = true
Im not sure how to approach this as if i disable the double tap gesture for the Collection View i cant double tap other cells. And i don't even know how to set it up so that double tap is only available in the cell and not the Collection View.
Upvotes: 4
Views: 6866
Reputation: 54600
You could set isEnabled
to false on the gesture recognizer.
You could implement UIGestureRecognizerDelegate
and return false from gestureRecognizerShouldBegin
.
Upvotes: 0
Reputation: 431
Disabling isUserInteractionEnabled
on any subview of your collectionView
will still pass events to the collectionView
(superview). So isUserInteractionEnabled
disables touch events on all subviews but not on superviews, which in this case is the collectionView.
You have a few options to proceed:
UICollectionViewCell
and add a UITapGestureRecognizer
to handle the double tap internally and then delegate the double tap event.didDoubleTap
method check to see if the cell that you just double tapped is enabled/disabled. You can do this by using indexPathForItemAtPoint:
and then cellForItemAtIndexPath:
.Upvotes: 3