我遇到了UICollectionView的问题,我认为我已经缩小到以下几个方面。问题是,当我在UICollectionView上调用重新加载时,会出现一个闪烁,加载1个图像,然后加载正确的图像。几乎就像当您滚动新单元格并更新它们但没有任何滚动时。
现在我用普通的
测试了它sampleImage.image = [UIImage imageNamed:@"LogoHome"];
我没有任何闪烁,所以我把它缩小到以下代码
[self.imageManager requestImageForAsset:[self.arrayPhotoAssets objectAtIndex:indexPath.row]
targetSize:CGSizeMake(imageWidth, imageHeight)
contentMode:PHImageContentModeAspectFill
options:nil resultHandler:^(UIImage *result, NSDictionary* info){
UIImageView *sampleImage = (UIImageView *)[cell viewWithTag:1];
sampleImage.image = result;
}];
位于
之内- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
有什么方法可以调整代码以防止上述情况发生?以下是完整的代码段:
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
////// GALLERY COLLECTION VIEW
if(collectionView.tag == 1){
static NSString *cellIdentifier = @"galleryCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
float imageWidth = 77;
float imageHeight = 77;
UIScreen *mainScreen = [UIScreen mainScreen];
//NSLog(@"%f",mainScreen.bounds.size.width);
// IPHONE 6
if(mainScreen.bounds.size.width == 375){
imageWidth = 92;
imageHeight = 92;
}
// IPHONE 6 PLUS
if(mainScreen.bounds.size.width == 414){
imageWidth = 102;
imageHeight = 102;
}
[self.imageManager requestImageForAsset:[self.arrayPhotoAssets objectAtIndex:indexPath.row]
targetSize:CGSizeMake(imageWidth, imageHeight)
contentMode:PHImageContentModeAspectFill
options:nil resultHandler:^(UIImage *result, NSDictionary* info){
UIImageView *sampleImage = (UIImageView *)[cell viewWithTag:1];
sampleImage.image = result;
}];
return cell;
}
UICollectionViewCell *cell;
return cell;
}
答案 0 :(得分:1)
我建议您在尝试拨打sampleImage.image = nil
之前设置requestImageForAsset
。这将清除您的图像视图,以消除闪烁。
UIImageView *sampleImage = (UIImageView *)[cell viewWithTag:1];
sampleImage.image = nil;
[self.imageManager requestImageForAsset:[self.arrayPhotoAssets objectAtIndex:indexPath.row]
targetSize:CGSizeMake(imageWidth, imageHeight)
contentMode:PHImageContentModeAspectFill
options:nil resultHandler:^(UIImage *result, NSDictionary* info){
sampleImage.image = result;
}];
答案 1 :(得分:0)
设置" isSynchronous"传递给requestImage(PHImageRequestOptions)的选项中的true为我修复了闪烁。