[英]Gesture recogniser is impacting other functionality
我有一個手勢識別器正在阻止 collectionView function 正常工作。 下面添加示例代碼。
視圖 controller 有一個集合視圖,可以像在 iPhone 主屏幕上刪除應用程序一樣刪除單元格。 用戶長按屏幕,收集單元格開始搖動,一旦點擊屏幕(不是在單元格的刪除按鈕上),就會停止搖動。
現在這個刪除功能正在工作,我不能再單擊單元格來打開一個帶有相關信息的新視圖 controller。 有沒有辦法添加條件,以便 tapRecognizer 僅在單元格晃動時發生,以便在點擊集合視圖中的單元格時,collectionView function 工作?
override func viewDidLoad() {
super.viewDidLoad()
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed))
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tapPressed))
self.collectionView.addGestureRecognizer(longPressRecognizer)
self.collectionView.addGestureRecognizer(tapRecognizer)
}
//Tap screen
@objc func tapPressed(sender: UITapGestureRecognizer) {
stopCellShaking()
}
//Open the information for the selected cell
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//Function to open new screen
showInformation(chosenCell: exampleList[indexPath.row])
}
有沒有辦法添加條件,以便 tapRecognizer 僅在單元格晃動時發生
絕對地。 通常,只需通過將其isEnabled
設置為false
來關閉點擊識別器。 當搖動開始(長按)時,將點擊手勢識別器的isEnabled
設置為true
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.