Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: `UICollectionview`, how to get a cell's `contentoffset` by it's `indexPath`

I'm using a UICollectionview with a circular layout. I'm trying to calculate the contentOffsetper item but with the circular layout the full contentsize does not seem match the content.

  • The collectionview's total contentSize = 780
  • The content offset of the last item = 397(?)
  • The content offset per item = 33(?)

Is there any way I can get the offset for an item by it's indexPath or at least the correct (397) value for the last item's in the collectionview? I got these values by testing and printing the contentoffset but I would like to calculate these numbers (33 and 397) by code without having to scroll.

So is there a way to calculate a cell's contentoffset(?) inside the collectionview by it's indexPath? Thanks!

like image 995
Steven B. Avatar asked May 30 '16 08:05

Steven B.


1 Answers

I found the problem, the contentsize of the scrollview is the size of the content + the size of the uicollectionview's frame. That was the reason the contentSize returned a larger size than the actual content was.

so: (contentSizeX - collectionviews frame X) / cells = contentOffset per item (780 - 383) / 12 => 33

like image 168
Steven B. Avatar answered Nov 14 '22 09:11

Steven B.