CollectionViewController 中的滚动问题 - Swift

Issue with scrolling in CollectionViewController - Swift

我在 collectionViewController 中水平滚动时遇到问题。

在 CellForItemA 中,我有以下内容,用于在每个水平单元格上绘制一些线条:

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let origine = CGPoint(x: 50.0, y: CGFloat(cell.view.frame.height - 100))
    createTextLayer()
    showLoads(withOrigine: origine, cellForItemAt: indexPath, scale_H: scale_H, scale_V: scale_V, inView: cell.view)
    return cell

我可以在每个单元格中绘制我想要的任何东西,但问题是 有时 我在单元格 1 中绘制的内容,例如,它在其他单元格中显示相同细胞.
这个问题只是在我快速移动Cells时出现,因为当我移动缓慢时我没有问题。

我尝试使用 prepareForReuse、willDisplay,但没有用。

有什么建议可以强制 collectionViewTable 一次只移动一个单元格吗?

可能是同一个小区,只是被系统重用了。您是否覆盖了 prepareForReuse 并清理了那里的层? https://developer.apple.com/reference/uikit/uicollectionreusableview

ReloadData 是collectionView 的一个函数。 https://developer.apple.com/reference/uikit/uicollectionview/1618078-reloaddata

我的问题已经被 Svein Halvor Halvorsen 解决了:

self.view.layer.sublayers?.forEach { [=10=].removeFromSuperlayer() }