how to get indexPath for cell which is located in the center of UICollectionView

前端 未结 11 2272
慢半拍i
慢半拍i 2020-12-25 09:41

How can i find indexPath for cell in the middle of UICollectionView?

I have horizontal scrolling and only one big cell<

11条回答
  •  盖世英雄少女心
    2020-12-25 10:19

    Like you did yourself, indexPathForItemAtPoint is a good way of finding the index path of the element you're interested in. If your question is: how do i know the coordinates of this point? Then you should try with (using the same name you gave it in your code snippet):

    initialPinchPoint = CGPointMake(self.collectionView.center.x + self.collectionView.contentOffset.x, 
                                    self.collectionView.center.y + self.collectionView.contentOffset.y);
    

提交回复
热议问题