ios – UICollectionView标题视图没有正确出列

前端之家收集整理的这篇文章主要介绍了ios – UICollectionView标题视图没有正确出列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试向集合视图添加标头.我正在使用水平滚动的自定义布局,它用于查看朋友的头像图像列表.我可以让标题出现,但它不会出列.一旦标题视图离开屏幕,它就会消失.任何人都可以弄清楚这是为什么?

谢谢!

集合查看数据源:

- (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,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;
}

解决方法

你显然使用的是我从未听说过的第三方布局.在与你讨论之后,我的感觉是我在你的问题下的第一个评论可能是正确的:布局本身可能是错误的.

在集合视图中,单元格的布局属性(位置,大小,变换,alpha等)是布局的责任.因此,如果某些东西仅仅因为它从屏幕上滚动然后重新开启而消失,那么听起来布局本身并没有正确地完成其工作.

猜你在找的Xcode相关文章