如何获取UICollectionViewCell的矩形? [英] How to get the rect of a UICollectionViewCell?

查看:165
本文介绍了如何获取UICollectionViewCell的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UITableView 的方法是 rectForRowAtIndexPath:,但这在UICollectionView中不存在。我正在寻找一个很好的干净方法来获取单元格的边界矩形,也许我可以在 UICollectionView 上添加一个类别。

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 bounding rectangle, perhaps one that I could add as a category on UICollectionView.

推荐答案

我发现这样做的最好方法如下:

The best way I've found to do this is the following:

UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath];

然后您可以通过 attributes.frame attributes.center

这篇关于如何获取UICollectionViewCell的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆