SDImageCache 占位符 gif
Posted
技术标签:
【中文标题】SDImageCache 占位符 gif【英文标题】:SDImageCache placeholder gif 【发布时间】:2014-07-31 18:46:57 【问题描述】:我正在尝试为我的SDImageCache
创建一个 gif 作为占位符。
所以我首先创建了 gif:
_imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.thumbnailImageView.frame.size.width,
cell.thumbnailImageView.frame.size.height)];
_imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Polygon 1 copy.bolt_00000"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00000"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00001"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00002"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00003"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00004"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00005"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00006"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00007"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00008"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00009"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00010"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00011"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00012"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00013"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00014.png"], nil];
_imageView.animationRepeatCount = 500;
然后我把它变成了UIimage
UIImage *imagety = _imageView.image; // get the UIImage
UIImage *otherImage = [UIImage imageNamed:@"Loadimage.png"]; // load another image
_imageView.image = otherImage; // change in the image in your UIImageView
接下来我把它作为占位符:
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache queryDiskCacheForKey:encodedString done:^(UIImage *image, SDImageCacheType cacheType)
if (image)
cell.thumbnailImageView.image = image;
else
[cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:encodedString] placeholderImage:imagety completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
[imageCache storeImage:image forKey:encodedString];
];
];
但这似乎不起作用?你有什么想法吗?
【问题讨论】:
您能否详细说明什么不完全有效?占位符图片没有显示,是吗? 占位符图片不显示!正确 【参考方案1】:如果检查_imageView.image
返回的值:
UIImage *imagety = _imageView.image;
你应该看到它是nil
。这是因为您使用animationImages
来处理视图中的动画。
您不能将UIImageView
(或与之关联的动画)用作 SDImage 中的占位符图像。
你可以使用:
UIImage *imagety = [UIImage animatedImageWithImages:
[NSArray arrayWithObjects:
[UIImage imageNamed:...],
nil]
duration:10.0f];
(docs)
animatedImageWithImages:duration:
从现有图像集创建并返回动画图像。
+ (UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration
【讨论】:
那么这不是将动画 gif 作为占位符的方式吗? 你能推荐另一种方式吗?以上是关于SDImageCache 占位符 gif的主要内容,如果未能解决你的问题,请参考以下文章