【问题标题】:Remove gesture for a specific tableview cell删除特定表格视图单元格的手势
【发布时间】:2019-05-20 18:43:22
【问题描述】:
【问题讨论】:
标签:
ios
swift
uitableview
uitapgesturerecognizer
uipangesturerecognizer
【解决方案1】:
好的,只有一种方法可以做到这一点:
class MyViewController: UIViewController {
@IBOutlet private var collectionView: UICollectionView!
private let panGesture = UIPanGestureRecognizer()
private let tapGesture = UITapGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
panGesture.delegate = self
tapGesture.delegate = self
// Code to assign Gesture Recognizer
}
}
// You should conform your controller to UIGestureRecognizerDelegate
extension MyViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
let touchLocation = touch.location(in: collectionView)
guard let indexPath = collectionView.indexPathForItem(at: touchLocation) else {
return true
}
// let's assume that you want to disable second cell (indexPath.row starts from 0)
let disabledRow = 1
return indexPath.row != disabledRow
}
}
如果您发布代码,我可以为您提供更好的帮助