【发布时间】:2020-10-30 00:11:31
【问题描述】:
我想知道是否有任何方法可以使用内容偏移量初始化自定义UICollectionView,以便当它第一次出现时集合视图是偏移量的?我尝试在我的自定义UICollectionView 的便捷初始化中设置内容偏移量,但这不会影响集合视图首次出现时的内容偏移量。谢谢
我的自定义类的便利初始化器:
convenience init() {
layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 0
self.init(frame: CGRect.zero, collectionViewLayout: layout)
self.backgroundColor = UIHelper.primaryBG
self.showsHorizontalScrollIndicator = false
contentInset = UIEdgeInsets(top: 0,
left: UIScreen.main.bounds.width / 2,
bottom: 0,
right: UIScreen.main.bounds.width / 2)
// Doesn't work
setContentOffset(CGPoint(x: UIScreen.main.bounds.width * 1.5, y: 0), animated: false)
self.register(MyCell.self, forCellWithReuseIdentifier: "cell")
self.delegate = self
self.dataSource = self
}
【问题讨论】:
-
你是想让collectionview滑入还是什么?这里的目标是什么
-
@Jay 我希望在集合视图出现时将集合视图滚动到末尾
-
如果我理解正确的话,当collectionview加载时,你希望它在屏幕上显示最后一个单元格吗?
-
是的,就像您要加载关注者列表并且当列表加载时它会滚动到底部。我正在寻找集合视图在集合视图出现时滚动到末尾
-
何不先将collectionview alpha设置为0,然后使用委托方法collectionView.scrollToItem(at:IndexPath(item: indexNumber, section: sectionNumber), at: .right, 动画: false) ,然后在collectionview alpha中淡入1,所以它会在底部?