Dinker Malhotra
Dinker Malhotra

Reputation: 37

Double tap Gesture on UICollectionViewCell?

I want to double tap on the UICollectionViewCell to like the profile just like OkCupid App. I have applied Tap Gesture on Collection View but it does not work.

When I try to double tap the cell every time didSelectCollectionViewCell Method call.

Upvotes: 1

Views: 5222

Answers (4)

Grzegorz
Grzegorz

Reputation: 31

The error which you got: Cannot call value of non-function type 'UICollectionView!' is because you have try to use wrong method.

Please try to use this one:

var selectedIndexPath: NSIndexPath = self.collectionView.indexPathForItemAtPoint(pointInCollectionView)

Upvotes: 3

Himan Dhawan
Himan Dhawan

Reputation: 924

apply the UITapGesture on UICollectionviewcell instead of UIcollectionView and handle the selection in custom UICollectionViewCell and set the property numberofTapsRequired equal to 2 .....

Upvotes: -1

Mayank Patel
Mayank Patel

Reputation: 3908

You have to add the double tap gesture recognizer to the collection view instead of the cell. In its action selector you could determine which cell was double tapped

override func viewDidLoad() {
     var doubleTapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "didDoubleTapCollectionView:")
     doubleTapGesture.numberOfTapsRequired = 2  // add double tap
     self.collectionView.addGestureRecognizer(doubleTapGesture)
}

func didDoubleTapCollectionView(gesture: UITapGestureRecognizer) {
     var pointInCollectionView: CGPoint = gesture.locationInView(self.collectionView)
     var selectedIndexPath: NSIndexPath = self.collectionView(forItemAtPoint: pointInCollectionView)
     var selectedCell: UICollectionViewCell = self.collectionView.cellForItemAtIndexPath(selectedIndexPath)
     // Rest code
}

Upvotes: 2

aduflo
aduflo

Reputation: 91

have you set the UITapGestureRecognizer property numberOfTapsRequired: to 2?

Upvotes: 1

Related Questions