当我点击表格 View 时,它将触发 touchesBegan
和 touchesShouldBegin
。不过,我的 View 单元格上还有一个 UIPanGestureRecognizer
,并且在平移单元格时,点击其他单元格不会触发 touchesShouldBegin
。
我需要 touchesShouldBegin
的原因是我想在平移单元格时停止触摸。我可以使用其他方法来做到这一点吗?我尝试将 allowsMultipleSelection
设置为 false
和 true
。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("This will always be printed")
}
override func touchesShouldBegin(_ touches: Set<UITouch>, with event: UIEvent?, in view: UIView) -> Bool {
print("This will only be printed when no cells are being panned")
return true
}
最佳答案
尝试将 UITableView
的 delaysContentTouches
属性设置为 true
。
您还可以尝试将 UIGestureRecognizerDelegate
添加到 UIPanGestureRecognizer
并具有:
extension MyViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
关于swift - UITableView 点击手势行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41116649/