gpt4 book ai didi

swift - UITableView 点击手势行为

转载 作者:行者123 更新时间:2023-11-30 12:50:03 25 4
gpt4 key购买 nike

当我点击表格 View 时,它将触发 touchesBegantouchesShouldBegin。不过,我的 View 单元格上还有一个 UIPanGestureRecognizer,并且在平移单元格时,点击其他单元格不会触发 touchesShouldBegin

我需要 touchesShouldBegin 的原因是我想在平移单元格时停止触摸。我可以使用其他方法来做到这一点吗?我尝试将 allowsMultipleSelection 设置为 falsetrue

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
}

最佳答案

尝试将 UITableViewdelaysContentTouches 属性设置为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com