ios - 如何获取 UICollectionViewCell 的矩形?

标签 ios uitableview ios6 uicollectionview

UITableView 有方法 rectForRowAtIndexPath:,但在 UICollectionView 中不存在。我正在寻找一种干净利落的方法来获取单元格的边界矩形,也许我可以将其添加为 UICollectionView 上的类别。

最佳答案

我发现执行此操作的最佳方法如下:

objective-C

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

swift

let attributes = collectionView.layoutAttributesForItem(at: indexPath)

然后您可以通过 attributes.frameattributes.center 访问该位置

关于ios - 如何获取 UICollectionViewCell 的矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12504924/

相关文章:

ios - 如何将 View 限制在 tableView 分隔符的边缘?

ios - UITableView 在更新 NSFetchedResultsController 时将滚动保持在正确的位置

ios - NSLineBreakMode 枚举和向后兼容性

ios - 侧边菜单 didSelect 方法在 Swift 中不起作用

java - java打印代码正在工作,发送到打印机但不打印任何内容(python中的java)

ios - 将 NSUInteger 添加到 NSMutableArray

cocoa-touch - 为什么表格 View 单元格中的自动布局会导致表格的内容大小错误地更改?

ios - iOS 5 中的键盘调整大小事件(中文键盘错误)?

iphone - UITableView 处于编辑模式 - 按删除键使我的应用程序崩溃

ios - iOS 6 Beta 3 (ipad 3) 中的 UIAlertView 似乎没有触发委托(delegate)中的代码