OGeek|极客世界-中国程序员成长平台

标题: ios - 我如何获得 UICollectionView 的 rect [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:56
标题: ios - 我如何获得 UICollectionView 的 rect

我想在 UICollectionView 中定位节标题的框架。我对 UITableView 也有类似的情况,为此,我可以通过以下方式获得它的正确性:

 CGRect rect = [self.tableView rectForHeaderInSection:section];

有没有办法在 UICollectionView 中获得相同的结果?谢谢!



Best Answer-推荐答案


对不起,伙计们。这实际上很容易。

 NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
 UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath];
 CGRect rect = [attributes frame];

关于ios - 我如何获得 UICollectionView 的 rect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27011572/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4