3

I have an iOS 14 collectionView, configured with compositional layout.

You can scroll vertically through the collectionView, and you can scroll horizontally within the sections.

I would like to know if there is a way to scroll programmatically, within a section? Something like collectionView.setContent(offset: 100, inSection: 2)

And is there a way to get the contentOffset of a particular section?

I can't find any function to do that.

Sincerely,

Jery

darksider
  • 1,030
  • 2
  • 14
  • 20

1 Answers1

1

Its a hack but for such sections the parent is a UIScrollView which you can get a reference to by referencing a cell in the section and then referencing its superview.

Like this:

let cell = collectionView.cellForItem(at: indexPath)!
let scrollView = cell.superview as! UIScrollView
scrollView.setContentOffset(<#CGPoint#>, animated: true)
Arbitur
  • 38,684
  • 22
  • 91
  • 128