【发布时间】:2020-09-29 21:45:18
【问题描述】:
所以我的每个 tableview 单元格都是全屏高度,类似于 tiktok、igtv 等。当用户滚动时,我希望 tableview 在每个单元格处停止,不能滚动一次并超过 2/3 个单元格。
我正在以编程方式使用自定义 tableview 单元,这就是我当前实现 tableview 委托和数据源功能的方式
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(PostViewTableCell.self, forCellReuseIdentifier: PostViewTableCell.cellReuseIdentifier)
tableView.allowsSelection = false
tableView.bounces = false
}
override var prefersStatusBarHidden: Bool {
return true
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel?.postInformations.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: PostViewTableCell.cellReuseIdentifier) as? PostViewTableCell else {
fatalError("Couldn't dequeue reusable cell")
}
cell.postViewCellOutput = self
cell.setUpCell(position: indexPath.row, viewModel: viewModel)
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.frame.size.height
}
所以我在单元格上调用 canPlay 以播放在屏幕上完全可见的单元格,以便它可以开始播放。我正在使用这种方法来检查可见性:
private func checkIfCellIsVisible(indexPath: IndexPath) -> Bool {
let cellRect = tableView.rectForRow(at: indexPath)
return tableView.bounds.contains(cellRect)
}
【问题讨论】:
-
这能回答你的问题吗? swift 3 ios tableview scroll by cell
-
不,我检查了那个问题,他们没有解决方案
-
您尝试接受的答案了吗?它看起来确实不错(虽然我没有尝试)
-
不行
标签: ios swift uitableview