How to get the rect of a UICollectionViewCell?

后端 未结 5 1845
北海茫月
北海茫月 2020-12-23 11:05

UITableView has the method rectForRowAtIndexPath:, but this does not exist in UICollectionView. I\'m looking for a nice clean way to grab a cell\'s

5条回答
  •  醉话见心
    2020-12-23 11:40

    in swift you can just do:

    //for any cell in collectionView
    let rect = self.collectionViewLayout.layoutAttributesForItemAtIndexPath(clIndexPath).frame
    
    //if you only need for visible cells
    let rect = cellForItemAtIndexPath(indexPath)?.frame
    

提交回复
热议问题