这是我的代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! imageUserCell
let coolGesture = UILongPressGestureRecognizer(target: self, action: #selector(detailedPerson.makeItCoolAction(_:)))
coolGesture.minimumPressDuration = 0.5
coolGesture.view?.tag = 4
cell.addGestureRecognizer(coolGesture)
这是功能代码:
func makeItCoolAction(sender: UIGestureRecognizer){
print(sender.view?.tag)
print("Photo cooled")
}
控制台打印相同的值:0,这是默认值。我强烈需要将 indexPath.row 值传递给 makeItCoolAction 但我看到 UIGestureRecognizer 没有 tag 属性但 .view 属性有它,正如您在代码中看到的那样。
我已将 makeItCoolAction 发件人从 UILongPressGestureRecognizer 更改为 UIGestureRecogizer 并且它仍然继续打印 0 值。