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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With