gpt4 book ai didi

ios - 未调用 UITableView 的触摸应取消功能

转载 作者:行者123 更新时间:2023-12-01 19:30:55 24 4
gpt4 key购买 nike

我有一个表格 View ,它在每个 TableView 单元格中有一个 UIImage 和一些 UIButton 对象。当我滚动表格 View 时,它总体上工作得很好。但是,如果我触摸其中一个 UIButton 项目来滚动表格 View ,则 UIButton 似乎会窃取触摸并且表格 View 不会滚动。相反,UIButton 项目似乎被选中。即使用户在开始滚动时触摸按钮,我也希望能够滚动表格 View 。所以,我在这里搜索了解决方案,尝试了以下方法。

extension UITableView {

override public func touchesShouldCancel(in view: UIView) -> Bool {

print("the touchesShouldCancel function is called.")

if view is UIButton {
return true
}

return super.touchesShouldCancel(in: view)
}

}
但是,它不起作用。每当我滚动表格 View 时,甚至都不会调用该函数。我在这里想念什么?非常感谢您的意见。谢谢大家。

最佳答案

子类 UITableView设置 TableView canCancelContentTouchestrue根据 Apple docs

The scroll view does not call this method if the value of thecanCancelContentTouches property is false

class YourTableView:UITableView {

override func awakeFromNib() {
canCancelContentTouches = true
delaysContentTouches = false
}

override func touchesShouldCancel(in view: UIView) -> Bool {

}
}

关于ios - 未调用 UITableView 的触摸应取消功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62853711/

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