ios - UICollectionView header View 未正确出队

标签 ios objective-c xcode ios7 uicollectionview

我正在尝试将 header 添加到 Collection View 。我正在使用水平滚动的自定义布局,它用于查看 friend 的头像图像列表。我可以让 header 出现,但它不会出队。一旦标题 View 离开屏幕,它就永远消失了。谁能弄清楚这是为什么?

谢谢!

Collection View 数据源:

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

头像 Collection View :

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

最佳答案

您显然在使用我从未听说过的第三方布局。在与您讨论后,我的感觉是我在您的问题下的第一条评论可能是正确的:布局本身可能有问题。

在 Collection View 中,单元格的布局属性(位置、大小、变换、alpha 等)由布局负责。因此,如果某些东西仅仅因为从屏幕上滚出然后又重新出现而消失,这听起来像是布局本身没有正确完成它的工作。

关于ios - UICollectionView header View 未正确出队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25068743/

相关文章:

ios - UI控件生命周期

iphone - 提高应用程序电池消耗效率的技巧。(iOS)

ios - 将 Nsurl 域名转换为我的国家/地区域名

ios - 在设备上构建时出现代码签名错误

iphone - TableView :commitEditingStyle:forRowAtIndexPath how to stop delete button from showing on some cells

ios - 将设备添加到由 Xcode 管理的供应配置文件

ios - JSQMessagesViewController 在聊天中不显示气泡图像

ios - 在iOS上将NSData转换为NSAttributedString

ios - 已处理的构建文件大小超过 100 MB 应用程序文件限制

ios - 控制台错误 : "react-native-maps" AirGoogleMaps dir must be added to your xCode project