双击UICollectionViewCell上的手势?

我想双击UICollectionViewCell来像OkCupid App那样喜欢这个configuration文件。 我已经在集合视图上应用了Tap Gesture,但它不起作用。

当我尝试每次didSelectCollectionViewCell方法调用时双击单元格。

您必须将双击手势识别器添加到集合视图而不是单元格。 在其动作select器中,您可以确定哪个单元格是双击的

 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 } 

你得到的错误:不能调用非函数types的值“UICollectionView!” 是因为你有尝试使用错误的方法。

请尝试使用这个:

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

你有没有设置UITapGestureRecognizer属性numberOfTapsRequired:到2?

应用UICollectionviewcell上的UITapGesture而不是UIcollectionView,并处理自定义UICollectionViewCell中的select,并将属性numberofTapsRequired设置为等于2 …..