Scrolling the Collectionview and select Items
How can i scroll to items and stay there instead of scrolling back to center? Is there a way to select an item and center the collection view to this item (like scrolling to this item).
@BlackM0nster You've probably figured it out by now, but just for posterity:
You can do this by increasing the collection view's content size, as well as its content offset.
I did something like this (I work in Swift on my side):
private let contentPadding = CGSize(width: 400, height: 400)
override var collectionViewContentSize: CGSize {
let bounds = collectionView.bounds.size ?? CGSize.zero
return CGSize(
width: (bounds.width * 2) + contentPadding.width,
height: (bounds.height * 2) + contentPadding.height)
}
func setContentViewContentOffset() {
collectionView?.contentOffset.x += contentPadding.width
collectionView?.contentOffset.y += contentPadding.height
}
and then be sure to call setContentViewOffset() at least once during setup. There are lots of magic numbers in that snippet, just play around with them to make it work for you.
Hi @phlippieb
Did you able to try this collection view in swift ?
Hello I have same issue like I can't scroll to some items and select. Please help me.