1

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.

Bista
  • 7,869
  • 3
  • 27
  • 55
Dinker Malhotra
  • 37
  • 1
  • 10

4 Answers4

3

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)
Grzegorz
  • 31
  • 5
2

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
}
Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
1

have you set the UITapGestureRecognizer property numberOfTapsRequired: to 2?

aduflo
  • 81
  • 4
-1

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

Himan Dhawan
  • 894
  • 5
  • 23