我正在创建一个UICollectionView
,我的自定义单元格将包含两个标签和一个图像。
每个图像都是异步下载的,因此在下载完成之前我不知道它的大小。 一旦下载完成,我想适应每个单元格以重新布局其内容和框架,以适合刚下载的图像的高度。
作为UICollectionViewLayout
,我正在使用CHTCollectionViewWaterfallLayout
为了异步下载图像,我正在使用SDWebImage,如下所示:
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{... some completion code here ...}];
问题:
在每个图像下载完成后,正确的方法是调整每个UICollectionViewCell
的大小吗?
[cell.imageView setFrame:CGRectMake(2,2,image.size.width,image.size.height])]; [UIView animateWithDuration:0.3f animations:^{ [self.collectionView.collectionViewLayout invalidateLayout]; }];
- Fmessina