水平UIcollectionView滚动从右向左开始

问题描述 投票:0回答:2

我确实希望视图在加载时先显示正确的单元格,然后我应该从那里向左滚动我尝试这段代码,但是没有用

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
    }

在加载视图时在这里喜欢这张照片,它显示了第一个右单元格

enter image description here

swift xcode uicollectionview uicollectionviewcell
2个回答
2
投票
由于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)


-1
投票
这不是UICollection视图的通常行为,但是如何旋转和翻转您的collectionView,那么最后一个单元格将是您的第一个;)。

如果有兴趣,请检查CGAffineTransform(Rotation angle)CGAffineTransform(TranslationY)

© www.soinside.com 2019 - 2024. All rights reserved.