我有集合视图作为表视图的行。集合视图仅支持水平滚动。当我滚动到第一行集合视图的末尾,然后滚动到 tableview 的底部时。最后一个集合视图也处于结束位置,当我还没有触及它时。
我知道这个问题是因为dequeueReusableCell
tableview。我试过使用prepareForReuse()
in UITableViewCell
。
我希望只要表视图的任何其他行都不受对表视图行的其余部分所做的交互的影响。
您可以使用表视图的委托方法存储(和恢复)集合视图的内容偏移量:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句