长按后如何在UICollectionViewCell上禁用UILongPressGestureRecognizer?

当前,我在cellForItemAt中的单元格上具有一个UILongPressGestureRecognizer的集合视图:

let longPress = UILongPressGestureRecognizer(target: self,action: #selector(handleLongPressOnCell))
    cell.addGestureRecognizer(longPress)

当用户按住某个单元格时,它会触发一个功能来显示名为cellDeleteAppear()的菜单。但是,菜单显示在屏幕上之后,用户可以按住另一个单元格,这将导致菜单再次弹出。

@objc func handleLongPressOnCell(_ sender: UILongPressGestureRecognizer) {
        if sender.state == .began {

            cellDeleteAppear()

            let gestureLocation = sender.location(in: self.trayCollectionView)

            if let indexPath = self.trayCollectionView.indexPathForItem(at: gestureLocation) {

            indexPathForDeletion = indexPath

            trayCollectionView.allowsSelection = false

            } else {
                print("long press error at index path")
            }
        }
    }

我的目标是:菜单处于活动状态时,用户不应按住另一个单元格来触发菜单弹出。任何帮助表示赞赏!

ASD52113144 回答:长按后如何在UICollectionViewCell上禁用UILongPressGestureRecognizer?

然后做

const t =  tX > 0
               ? 0
               : tX < width - width * scale
               ? width - width * scale
               : tX

当你隐藏它的时候

const t = Math.max(Math.min(tX,0),width - width * scale)
本文链接:https://www.f2er.com/2959858.html

大家都在问