UITableView
有方法 rectForRowAtIndexPath:
,但在 UICollectionView 中不存在。我正在寻找一种干净利落的方法来获取单元格的边界矩形,也许我可以将其添加为 UICollectionView
上的类别。
最佳答案
我发现执行此操作的最佳方法如下:
objective-C
UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath];
swift
let attributes = collectionView.layoutAttributesForItem(at: indexPath)
然后您可以通过 attributes.frame
或 attributes.center
访问该位置
关于ios - 如何获取 UICollectionViewCell 的矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12504924/