【发布时间】:2017-06-29 21:12:03
【问题描述】:
我在我的 iOS 应用程序中使用SDWebImage 在UICollectionView 进行图像缓存。
一切都很好,但是,当用户在集合视图上快速滚动时,在占位符被缓存图像替换之前总是有一点停顿。我相信这是由于缓存检查。为了更好的用户体验,一旦图像被实际缓存,我希望单元格显示正确的图像而不是占位符。如果我可以获取缓存图像的本地(设备)文件系统路径并将其存储在 Show 实例中,并使用它(如果存在)而不是我的占位符,这将很容易。
有pass success block to the setImageWithURL method 的可能性但是,它得到的唯一参数是UIImage 实例(实际上在master 分支中还有一个名为cached 的BOOL 变量正在也通过了)。那么 - 是否有可能直接从 UIImage 实例获取图像的文件系统路径?或者我应该修改 SDWebImage 以便将这些信息传递给缓存的实例?或者有没有更好的方法来实现我之前描述的目标?
我的 Show 类有 imageURL,下面是显示单元如何使用 SDWebImage:
#import "ShowCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
@implementation ShowCell
@synthesize imageView = _imageView;
@synthesize label = _label;
@synthesize show = _show;
- (void)setShow:(Show *)show
{
if (_show != show) {
self.label.text = show.title;
if (show.imageURL) {
[self.imageView setImageWithURL:[NSURL URLWithString:show.imageURL]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}
_show = show;
}
}
@end
【问题讨论】:
标签: ios uiimage sdwebimage