我正在开发应用程序,其中我需要与hooked story app
类似的UICollectionview的动态单元格大小。
上图显示我需要的东西。我尝试过其他自定义库,例如
WaterfallCollectionView
,MosaicLayout
,FMMosaicLayout
,greedo-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加载的,因此在加载图像之前我无法预测该单元格的大小。 所以请帮帮我。谢谢你。
答案 0 :(得分:0)
跟踪索引路径上的图像是否已下载。如果已下载然后返回下载的图像大小,则返回一些静态图像高度或只返回CGSizeZero
。下载图像时不要忘记重新加载单元格。我可以建议您提供哪些信息。