我在另一个UIControllerViewController
内有一个UIScrollView
。到目前为止,事情显示得很好,但我想实现一些事情,以便UIControllerViewController
的标题贴在顶端。
我在这里尝试UICollectionView
粘贴标头解决方案:
http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using
但是无法为这个案子工作。
我的UIControllerViewController
正在生成标题:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
ARCollectionHeaderView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader) {
_headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header" forIndexPath:indexPath];
_headerView.titleLabel.text = self.title;
reusableview = _headerView;
}
return reusableview;
}
并UIControllerViewController
添加到UIScrollView
,如此:
CGRect screenRect = [[UIScreen mainScreen] bounds];
UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setMinimumInteritemSpacing:0.0f];
[flowLayout setMinimumLineSpacing:0.0f];
[flowLayout setSectionInset:UIEdgeInsetsZero];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[flowLayout setHeaderReferenceSize:CGSizeMake(screenRect.size.width, 60)];
[flowLayout setItemSize:CGSizeMake(screenRect.size.width, 80)];
_articleList = [[AREmbeddedCollectionViewController alloc] initWithCollectionViewLayout:flowLayout]];
_articleList.title = @"In Greater Depth";
[_articleList.collectionView registerClass:[ARSimpleCollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
[self addChildViewController:_articleList];
[self.scrollView addSubview:_articleList.collectionView];
[_articleList didMoveToParentViewController:self];