我如何获得 UICollectionView 的 rect [英] How do I get rect for UICollectionView

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

问题描述

我想在 UICollectionView 中定位部分标题的框架.我对 UITableView 有类似的情况,为此,我可以通过以下方式获得它的 rect:

I want to locate the frame of section header in UICollectionView. I have a similar situation for UITableView, and for that, I was able to get its rect by doing:

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

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

Is there a way to get the same result in UICollectionView? Thanks!

推荐答案

抱歉,各位.其实很简单.

Sorry, guys. It was actually easy.

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

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

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