Boo*_*unz 8 xcode cocoa-touch uitableview uiscrollview swift
我在以这种方式创建的测试项目中有UITableView:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tableView.delegate = self
tableView.dataSource = self
}
// height?
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//return cellHeightWithoutSeparator + cellSeparatorHeight
//print("YES!")
return 80 // arbitrary
}
// table wants a UITableViewCell for each row
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomCell
// customize cell here
return cell
}
// how many rows?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50 // arbitrary
}
}
Run Code Online (Sandbox Code Playgroud)
表视图的结构是:
所以,你可以看到单元格包含一个按钮.
我希望按钮(或任何可单击的视图是单元格的子视图)立即响应触摸事件,因此我在故事板中的ScrollView属性检查器中取消选中"延迟触摸".
我的理解是,取消选中该框等同于代码:
tableView.delaysContentTouches = false
Run Code Online (Sandbox Code Playgroud)
根据文档,这种方法应该适用于IOS 2.0+
但是将此属性设置为true或false仅在IOS 11和12上按预期工作,但在IOS 10上(可能更早),就好像该框从未取消选中并且触摸按钮仍然延迟.
据我所知,仍然可以在单元格中创建"可点击"视图,并立即响应"内部触摸"(因为触摸事件将取消触摸时的延迟),但我仍然希望触摸向下事件立即拨打(在所有的IOS版本,不只是11+),因为:
1)我希望重新订购控制立即响应
2)我希望在单元格中的视图上具有正常/立即触摸的视觉反馈
我也咨询了4年前写的类似但不一样的问题,我尝试应用答案,但这些答案似乎都不适用于现代问题的原因.
有谁知道原因和(最好是Swift)解决方案吗?
| 归档时间: |
|
| 查看次数: |
158 次 |
| 最近记录: |