如何创建UICollectioview Cell动态大小,如钩子应用程序

时间:2016-09-30 08:27:26

标签: ios objective-c uicollectionview uicollectionviewcell uicollectionviewlayout

我正在开发应用程序,其中我需要与hooked story app类似的UICollectionview的动态单元格大小。Dynamic Cell

上图显示我需要的东西。我尝试过其他自定义库,例如 WaterfallCollectionViewMosaicLayoutFMMosaicLayoutgreedo-layout

使用Collectionview委托方法

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
     return [self sizeForPhotoAtIndexPath:indexPath];
}

-(CGSize )sizeForPhotoAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage *image = [imageArray objectAtIndex:indexPath.row];
    return CGSizeMake(image.size.width, image.size.height);
}

但是我的照片是从API加载的,因此在加载图像之前我无法预测该单元格的大小。 所以请帮帮我。谢谢你。

1 个答案:

答案 0 :(得分:0)

跟踪索引路径上的图像是否已下载。如果已下载然后返回下载的图像大小,则返回一些静态图像高度或只返回CGSizeZero。下载图像时不要忘记重新加载单元格。我可以建议您提供哪些信息。

相关问题