gpt4 book ai didi

ios - 重新加载和调用 requestImageForAsset 时 UICollectionView 闪烁

转载 作者:行者123 更新时间:2023-11-29 00:42:13 24 4
gpt4 key购买 nike

我有一个 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;

}

最佳答案

我建议您在尝试调用 requestImageForAsset 之前设置 sampleImage.image = nil。这将清除您的 ImageView ,从而消除闪烁。

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;
}];

关于ios - 重新加载和调用 requestImageForAsset 时 UICollectionView 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39179656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com