【发布时间】:2016-01-22 04:48:16
【问题描述】:
我想双击 UICollectionViewCell 以像 OkCupid 应用程序 一样喜欢个人资料。我在收藏视图上应用了点击手势,但它不起作用。
当我每次尝试双击单元格时,didSelectCollectionViewCell 方法调用。
【问题讨论】:
标签: ios swift uicollectionviewcell uitapgesturerecognizer
我想双击 UICollectionViewCell 以像 OkCupid 应用程序 一样喜欢个人资料。我在收藏视图上应用了点击手势,但它不起作用。
当我每次尝试双击单元格时,didSelectCollectionViewCell 方法调用。
【问题讨论】:
标签: ios swift uicollectionviewcell uitapgesturerecognizer
你得到的错误:无法调用非函数类型'UICollectionView!'的值是因为你尝试使用了错误的方法。
请尝试使用这个:
var selectedIndexPath: NSIndexPath = self.collectionView.indexPathForItemAtPoint(pointInCollectionView)
【讨论】:
您必须将双击手势识别器添加到集合视图而不是单元格。在其动作选择器中,您可以确定双击哪个单元格
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
}
【讨论】:
您是否将UITapGestureRecognizer 属性numberOfTapsRequired: 设置为2?
【讨论】:
在 UICollectionviewcell 而不是 UIcollectionView 上应用 UITapGesture 并在自定义 UICollectionViewCell 中处理选择并将属性 numberofTapsRequired 设置为 2 ... ..
【讨论】: