请看看这个项目:https://github.com/betzerra/MosaicLayout
我不确定100%是否会完全满足你的要求,但在最糟糕的情况下,它可能会帮助你编写自定义UICollecionViewFlowLayout(这是实现你的目标的唯一方法)。
如果你的图像是在一个数组中,你可以简单地引用图像的大小,并从这里进行单元大小的调整:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image = [imageArray objectAtIndex:indexPath.row];
//You may want to create a divider to scale the size by the way..
return CGSizeMake(image.size.width, image.size.height);
}