【问题标题】:How to remove long gesture in UIcollectionViewCell particular cell on selection cell?如何在选择单元格上的 UIcollectionViewCell 特定单元格中删除长手势?
【发布时间】:2017-11-29 10:26:38
【问题描述】:

我已经像这样添加了Long gesture

longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture))

longPress.minimumPressDuration = 0.25
collectionview.addGestureRecognizer(longPress)

如何去除长手势?

【问题讨论】:

标签: ios swift


【解决方案1】:

找到单元格和添加到单元格的手势列表,然后删除您想要的手势..

let cell:UICollectionViewCell =  collectioView.cellForItem(at: IndexPath(row: 5, section: 0))!


        for ges in cell.gestureRecognizers!{
            if ges is UILongPressGestureRecognizer{
               cellView.removeGestureRecognizer(ges)
            }
        }

【讨论】:

  • 我想删除collectionview单元格上的长手势假设5行
【解决方案2】:

您可以在单元格准备好显示之前移除手势。

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        if let gesture = cell.gestureRecognizers?.filter({ (gesture) -> Bool in return  gesture is UILongPressGestureRecognizer }).first {
            cell.removeGestureRecognizer(gesture)
        }
    }

【讨论】:

    【解决方案3】:

    您正在为整个集合视图添加手势识别器。

    所以,如果您只希望一个单元格不响应长手势,则对于该特定单元格禁用手势识别器(使用 touchesBegan 回调来检查单元格内发生的触摸事件,如果是,则通过代码处理事件你希望)。

    如果您希望在多个单元格上使用此功能,请为每个需要单独识别器的单元格添加手势识别器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      相关资源
      最近更新 更多