我确实希望视图在加载时先显示正确的单元格,然后我应该从那里向左滚动我尝试这段代码,但是没有用
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! customCell
cell.data = self.data[indexPath.row]
self.collectionView.scrollToItem(at: IndexPath(item: self.data.count, section: 0) as IndexPath, at: .right, animated: false)
return cell
}
在加载视图时在这里喜欢这张照片,它显示了第一个右单元格
UICollectionView
从右向左平均水平滚动,因此您可以设置收藏夹视图,使其显示为最大向右滚动!这样用户就可以开始从右向左滚动YourCollectionView
是您所需的CollectionView的名称
[YourObjectListData
是该集合视图的数据源]
self.YourCollectionView.reloadData()
self.YourCollectionView.scrollToItem(at: NSIndexPath(item: self.YourObjectListData.count - 1, section: 0) as IndexPath, at: .right, animated: false)
如果有兴趣,请检查CGAffineTransform(Rotation angle)
和CGAffineTransform(TranslationY)
。