【发布时间】:2019-01-09 15:08:49
【问题描述】:
编辑: 问题解决了。我关注了一个关于如何从 LBTA 构建 Youtube 的 Youtube 教程。
我的 homeController 包含 4 个可以水平滚动的单元格。每个单元格(也是 UICollectionViewCell)都有不同的获取方法来从 Firebase 加载数据。
我有以下滚动代码:
// 在我的 setupCollectionView 中
if let flowLayout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout {
flowLayout.scrollDirection = .horizontal
flowLayout.minimumLineSpacing = 0
}
我也有:
override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let index = Int(targetContentOffset.pointee.x / view.frame.width)
let indexPath = IndexPath(item: index, section: 0)
menuBar.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)
setTitleForIndex(index: index)
}
我有一个附加到 collectionView 的菜单栏,菜单栏工作正常。但 UICollectionViewCell 没有。
当我通过左右滚动来测试它时,索引号到处都是。例如,当我滚动到第一个单元格时,它显示 2 或 3,或者有时什么也不显示。当我尝试在第一个单元格处向左滚动时,我仍然看到单元格编号发生了变化。
我想问一下在我的案例中识别单元格的适当方法是什么?请提供一些示例代码。谢谢。下图显示了我目前的状态。
【问题讨论】:
-
请提供您如何滑动单元格的代码以及委托回调。滑动手势是在 customCells 中还是来自 collectionView?
-
我没有滑动手势。我使用滚动方向 = .horizontal。请查看修改后的代码。
-
我没有看到您的编辑。另外,当你的意思是水平滚动时,你不应该说水平滑动。
-
感谢您的评论。我刚刚将其更新为从滑动滚动