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

前端 未结 11 2240
慢半拍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:13

    Here's what I did in Swift 3

    private func findCenterIndex() {
        let center = self.view.convert(self.collectionView.center, to: self.collectionView)
        let index = collectionView!.indexPathForItem(at: center)
        print(index ?? "index not found")
    }
    

提交回复
热议问题