我正在尝试向集合视图添加标头.我正在使用水平滚动的自定义布局,它用于查看朋友的头像图像列表.我可以让标题出现,但它不会出列.一旦标题视图离开屏幕,它就会消失.任何人都可以弄清楚这是为什么?
谢谢!
集合查看数据源:
- (UICollectionReusableView *)collectionView:(SWAvatarViewerCollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { if (self.showAddAvatarHeaderView && [kind isEqualToString:UICollectionElementKindSectionHeader]) { return [collectionView dequeueAddAvatarViewHeaderForIndexPath:indexPath]; } return nil; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(SWAvatarViewerCollectionViewFlowLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { if (!self.showAddAvatarHeaderView) { return CGSizeZero; } return CGSizeMake(kSWAvatarViewerAddAvatarHeaderViewWidth,CGRectGetHeight(collectionView.bounds)); }
头像集合视图:
- (SWAvatarViewerAddAvatarHeaderView *)dequeueAddAvatarViewHeaderForIndexPath:(NSIndexPath *)indexPath { SWAvatarViewerAddAvatarHeaderView *headerView = [super dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[SWAvatarViewerAddAvatarHeaderView headerReuseIdentifier] forIndexPath:indexPath]; headerView.delegate = self; return headerView; }
[self registerNib:[SWAvatarViewerAddAvatarHeaderView nib] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[SWAvatarViewerAddAvatarHeaderView headerReuseIdentifier]];
布局:
#pragma mark - Initialization - (void)configureFlowLayout { self.scrollDirection = UICollectionViewScrollDirectionHorizontal; // Padding for cells is taken into account in the cell's layout. Remove all // padding between cells self.sectionInset = UIEdgeInsetsMake(0,00.0f,00.0f); self.minimumLineSpacing = 0.0f; self.minimumInteritemSpacing = CGFLOAT_MAX; _cellBottomLabelFont = [UIFont systemFontOfSize:12.0]; CGSize defaultAvatarSize = CGSizeMake(44.0f,44.0f); _avatarViewSize = defaultAvatarSize; _springinessEnabled = YES; _springResistanceFactor = 1000; }