在UIScrollView内的UIControllerView中粘贴标头?

时间:2014-02-25 15:47:10

标签: ios objective-c uiscrollview uicollectionview

我在另一个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];

0 个答案:

没有答案