gpt4 book ai didi

ios - 从解析加载缓存图像时出现 Buggy UICollectionView

转载 作者:行者123 更新时间:2023-11-29 12:09:41 24 4
gpt4 key购买 nike

我有一些正在解析的图像。 (5 个对象每个都有一个 PFFile,每个图像大约 800x800 400Kb)。当我第一次在我的设备 (iphone 5S) 上运行该应用程序时,图像加载,一切正常。当我向下滚动以加载所有内容时。然后我再次向上滚动并更早加载图像(至少一次并通过解析缓存)UICollectionView 闪烁了一点(不太慢但很明显,就像 UI 试图跟上拖动)。我有什么我想念的吗?

*编辑 1:非常感谢对我的代码的任何帮助或改进

调用 CustomCell:

 static NSString *cellIdentifier = @"cellImage";
cellTypeImage1 *cell = (cellTypeImage1 *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
[cell configureWithObject:[self.collectionView objectAtIndex:indexPath]];
return cell;

自定义单元格内

    - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {


self.fullResImage = [[UIImageView alloc] init];
self.fullResImage.frame = CGRectZero;
[self addSubview:self.fullResImage];

}
self.backgroundColor = [color whiteColor];
return self;
}

-(void)layoutSubviews{
[super layoutSubviews];

self.fullResImage.frame = CGRectMake(0, 50, self.frame.size.width, self.frame.size.width);

}
- (void)prepareForReuse {
[super prepareForReuse];
self.fullResImage.image = nil;

}
-(void)configureWithObject:(PFObject*)object{


[object[@"image"] getDataInBackgroundWithBlock:^(NSData *data, NSError*error){
if (!error) {

/*THE PROBLEM IS HERE*/
self.fullResImage.image = [UIImage imageWithData:data];
/*When i replace it by a local image [UIImage imageNamed:@"LARGE IMAGE ABOUT 1.2MB"] everything runs smoothly*/
}else{
[ParseErrorHandlingController handleParseError:error];
}}];

}

最佳答案

尝试使用 PFImageView 而不是 UIImageView。

if (object) {
cell.image.file = [object objectForKey:@"image"];
if ([cell.image.file isDataAvailable]) {
[cell.image loadInBackground];
}
}

在单元格内下载图片时,记得在 prepareForReuse 中取消当前下载,否则快速滚动时会看到一些重复的内容。

我相信 PFImageView 会为你处理这个。

关于ios - 从解析加载缓存图像时出现 Buggy UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33850081/

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