IOS中uicollectionview有没有headerview

tableview有tableheaderview,uicollectionview有没有与之相似的"cllection headerview"?我知道uicollectionview可以设置每个分组的页眉页脚,但没找到整个uicollectionview上面的headerView,上面要加个轮播图。

UICollectionView作为比UITableView更强大的封装,自然是有header和footer的。
UICollectionView有一个delegate,

  • (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

这个方法中可以生成一个UICollectionReusableView,顾名思义是一个可重用的view,与UITableView中重用cell的意思一样。
这个UICollectionReusableView有两种不同类型,分别是UICollectionElementKindSectionHeader和UICollectionElementKindSectionFooter,这就是你要找的header和footer了。

一个UICollectionReusableView的生成例子如下

UICollectionReusableView *view = [_collectionView
dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:TheReuseID
forIndexPath:indexPath];

有 UICollectionReusableView

有,但是需要注册才能使用,给你推荐一个博客
iOS:UICollectionView的构建及使用
你到时候搜吧,刚写的,还没审批

我想问问如何让设置好的headerview跟tableview的headerview一样滑动的时候能停留。

设置
self.sectionHeadersPinToVisibleBounds=YES;