【发布时间】:2019-12-06 22:02:20
【问题描述】:
目前,我在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")
}
}
}
我的目标是:当菜单处于活动状态时,用户不应该能够按住另一个单元格来触发菜单弹出。任何帮助表示赞赏!
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell uigesturerecognizer