简体   繁体   中英

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 contentOffset per 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM