LEWatchLayout icon indicating copy to clipboard operation
LEWatchLayout copied to clipboard

Scrolling the Collectionview and select Items

Open BlackM0nster opened this issue 10 years ago • 3 comments

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 avatar Sep 23 '15 10:09 BlackM0nster

@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.

phlippieb avatar Nov 16 '16 10:11 phlippieb

Hi @phlippieb

Did you able to try this collection view in swift ?

ektapadaliya avatar Sep 12 '18 08:09 ektapadaliya

Hello I have same issue like I can't scroll to some items and select. Please help me.

ektapadaliya avatar Sep 12 '18 09:09 ektapadaliya