【发布时间】:2014-09-23 23:29:57
【问题描述】:
我正在尝试向集合视图添加标题。我正在使用水平滚动的自定义布局,它用于查看朋友的头像图像列表。我可以让标题出现,但它不会出队。一旦标题视图离开屏幕,它就永远消失了。谁能弄清楚这是为什么?
谢谢!
集合查看数据源:
- (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;
}
Nib 文件注册:
[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, 0, 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;
}
【问题讨论】:
-
这与“出队”无关。如果出现标题视图,它将出列(或至少出现)。如果它在滚动到屏幕外后消失,则与 NSCollectionViewLayout 有关。但是你没有说那是什么,所以你没有提供任何相关信息。
-
所以它毕竟不是自定义布局?只是普通的内置流式布局?
-
它只是一个调整过的流布局,带有一些 UIKitDynamics 以在单元格之间添加弹簧,但它本质上是一个水平流布局。
-
您是否在自定义布局中覆盖 prepareLayout?如果没有,您可能需要这样做并确保您的标题视图具有正确的框架。
标签: ios objective-c xcode ios7 uicollectionview