Ios 如何使用SDWebImage为多个大小的图像缓存图像
从我的web服务中,我获得了多个大小的图像。我正在TableView中加载它们。当我加载它们时,尚未缓存的新图像在占位符和原始图像之间闪烁,或者有时图像看起来比通常的大小小。但只要向下或向上滚动一点就可以解决问题,但我希望它们从一开始就保持原来的大小。但我想它会在下一次以原始形状出现,因为图片已经被缓存了 最初 稍微滚动一下之后 cellForRowAtIndexPath中的我的代码:Ios 如何使用SDWebImage为多个大小的图像缓存图像,ios,image,caching,sdwebimage,Ios,Image,Caching,Sdwebimage,从我的web服务中,我获得了多个大小的图像。我正在TableView中加载它们。当我加载它们时,尚未缓存的新图像在占位符和原始图像之间闪烁,或者有时图像看起来比通常的大小小。但只要向下或向上滚动一点就可以解决问题,但我希望它们从一开始就保持原来的大小。但我想它会在下一次以原始形状出现,因为图片已经被缓存了 最初 稍微滚动一下之后 cellForRowAtIndexPath中的我的代码: [cell.image sd_setImageWithURL:[NSURL URLWithString:[
[cell.image sd_setImageWithURL:[NSURL URLWithString:[NSMutableString stringWithFormat:@"%@app/media/access/pictures?p=%@",baseurl,data.picPath]]
placeholderImage:[UIImage imageNamed: @"image_loader.gif"]];
NSURL *filePath = [NSURL URLWithString:[NSMutableString stringWithFormat:@"%@app/media/access/pictures?p=%@",baseurl,data.picPath]];
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:filePath];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
self.img = image;
if (self.img.size.width > CGRectGetWidth(self.view.bounds)) {
CGFloat ratio = self.img.size.height / self.img.size.width;
return CGRectGetWidth(self.view.bounds) * ratio+140;
} else {
return self.img.size.height+180;
}
if(image != NULL)
{
self.img = image;
}
else
{
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:filePath
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
// do something with image
self.img = image;
}
}];
}
然后在高度FORROWATINDEXPATH中:
[cell.image sd_setImageWithURL:[NSURL URLWithString:[NSMutableString stringWithFormat:@"%@app/media/access/pictures?p=%@",baseurl,data.picPath]]
placeholderImage:[UIImage imageNamed: @"image_loader.gif"]];
NSURL *filePath = [NSURL URLWithString:[NSMutableString stringWithFormat:@"%@app/media/access/pictures?p=%@",baseurl,data.picPath]];
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:filePath];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
self.img = image;
if (self.img.size.width > CGRectGetWidth(self.view.bounds)) {
CGFloat ratio = self.img.size.height / self.img.size.width;
return CGRectGetWidth(self.view.bounds) * ratio+140;
} else {
return self.img.size.height+180;
}
if(image != NULL)
{
self.img = image;
}
else
{
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:filePath
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
// do something with image
self.img = image;
}
}];
}
我访问了他们的常见问题部分,他们提到了这个问题,但建议的解决方案对我不起作用 实际上,我检查了图像是否已经缓存,如果没有,我已经在heightForRowAtIndexPath下异步下载了它:
[cell.image sd_setImageWithURL:[NSURL URLWithString:[NSMutableString stringWithFormat:@"%@app/media/access/pictures?p=%@",baseurl,data.picPath]]
placeholderImage:[UIImage imageNamed: @"image_loader.gif"]];
NSURL *filePath = [NSURL URLWithString:[NSMutableString stringWithFormat:@"%@app/media/access/pictures?p=%@",baseurl,data.picPath]];
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:filePath];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
self.img = image;
if (self.img.size.width > CGRectGetWidth(self.view.bounds)) {
CGFloat ratio = self.img.size.height / self.img.size.width;
return CGRectGetWidth(self.view.bounds) * ratio+140;
} else {
return self.img.size.height+180;
}
if(image != NULL)
{
self.img = image;
}
else
{
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:filePath
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
// do something with image
self.img = image;
}
}];
}
是否有imageview大小在单元格中是固定的?没有imageview大小根据图像大小是动态的我不知道这个答案是如何有用的是任何处理多个大小图像的方法。