0

Im having a hard time trying to get notified and consequently run code whenever my horizontal carousel built with UICollectionViewCompositionalLayout changes to another cell / carousel item (aka the user scrolls to another carousel item). Upon googling, I found that I could do this with UIScrollView / UICollectionView delegate funcs such as scrollViewDidEndDecelerating, scrollViewDidScroll, etc. but turns out that these aren't called at all on horizontal UICollectionViews made with CompLayout.

Upon further googling, it turns out that there's a handler that can be set on the NSCollectionLayoutSection that does seem to get called the minute the user starts scrolling (visibleItemsInvalidationHandler). This closures gives me access to properties such as items, contentOffset and environment, though Im truly not sure how could I use these values to determine exactly the moment where the user changes to another cell. Im under the impression I need to do some manual calculations with the provided contentOffset the handler provides, but im quite lost honestly on what those calculations might be. The UICollectionView is using a .groupPaging orthogonalScrollingBehavior

Any tip is super welcomed. Thanks!

stompy
  • 227
  • 1
  • 13

0 Answers0