【问题标题】:Is there a way to prefetch images via Haneke?有没有办法通过 Haneke 预取图像?
【发布时间】:2015-07-04 10:54:06
【问题描述】:
在 SDWebImage 中,可以像这样预先获取(提前加载)图像:
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:<NArray with image URLs>];
请问有没有办法用Haneke 达到同样的效果?
似乎有一个Preload policy,但不确定如何使用它,例如HNKPreloadPolicyAll
【问题讨论】:
标签:
ios
objective-c
haneke
【解决方案1】:
我今天需要这个功能,我发现如果你遍历你的 URL 数组并使用临时 UIImageView 调用 hnk_setImageFromURL,图像会被缓存。
- (void) cacheImagesInURLs:(NSArray <NSString*>*)array;
{
for (NSString *path in array) {
UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kMaxWidth, kMaxHeight)];
tempImageView.hnk_cacheFormat = [self setImageCacheFormat];
[tempImageView hnk_setImageFromURL:[NSURL URLWithString:path] placeholder:nil];
}
}