Overload -setImageWithURL to delay setting of placeholder image until after loading
This commit is contained in:
parent
8fe72023dc
commit
12715da31b
|
@ -120,7 +120,7 @@
|
|||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
|
@ -133,6 +133,24 @@
|
|||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView 'image' with an 'url', placeholder and custom options.
|
||||
*
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param delayPlaceholder The value that determines if the placeholder is loaded while the image is fetched,
|
||||
* or after the image fails to load.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param progressBlock A block called while image is downloading
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder delayPlaceholderLoad:(BOOL)delayPlaceholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Download an array of images and starts them in an animation loop
|
||||
*
|
||||
|
|
|
@ -39,10 +39,16 @@ static char operationArrayKey;
|
|||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url placeholderImage:placeholder delayPlaceholderLoad:NO options:options progress:progressBlock completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder delayPlaceholderLoad:(BOOL)delayPlaceholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self cancelCurrentImageLoad];
|
||||
|
||||
self.image = placeholder;
|
||||
|
||||
|
||||
if (!delayPlaceholder) {
|
||||
self.image = placeholder;
|
||||
}
|
||||
|
||||
if (url) {
|
||||
__weak UIImageView *wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
|
@ -52,6 +58,11 @@ static char operationArrayKey;
|
|||
if (image) {
|
||||
wself.image = image;
|
||||
[wself setNeedsLayout];
|
||||
} else {
|
||||
if (delayPlaceholder) {
|
||||
wself.image = placeholder;
|
||||
[wself setNeedsLayout];
|
||||
}
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
|
|
Loading…
Reference in New Issue