3

I have a UICollectionView that scrolls horizontally. As I scroll left or right I would like to be able to determine when the most left or first cell is say, 60% off the screen and 40% on screen.

Eventually, I would like to do the same for when I scroll to the right and determine the same for the last cell or most right cell.

Thanks for the help.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
Changerrs
  • 273
  • 1
  • 4
  • 17
  • 1
    You should be able to get the `contentOffset` of the `UICollectionView`. You could use `visibleCells()` to know which cells are visible. Then if your collection is "simple", the one at the left should be the one with the "lower" indexPath and the more at the right the one at the "higher" indexPath. You could retrieve their frame and do a simple calculation (treat it as a maths/geometry excercise). Now, if all your cells have the same width, it's even more simple according to the contentOffset. – Larme Dec 08 '17 at 18:31
  • @Larme thanks for the feedback. I will give this a try. I am currently using the visible cells to check if a cell is 100% visible and if its frame exists in its parent frame. – Changerrs Dec 08 '17 at 18:38
  • @Changerrs - check this answer... not *exactly* what you're asking, but possibly the right direction: https://stackoverflow.com/a/46833430/6257435 – DonMag Dec 08 '17 at 20:48
  • @Changerrs, have you got the answer yet? mind to share? – wes. i Jul 25 '20 at 18:02

0 Answers0