SdWebImage download thumbnail and then download high resolution

I want to set the url and high resolution of the thumbnail image to load the first thumbnail, and then the high resolution image will load

+4
source share
3 answers

In fact, you don't need to create hidden UIImageView to do the trick.

What you need to do is set the first URL (with a smaller image), which will be directly loaded into your UIImageView , and then use SDWebImageManager to load the larger version in the background. When it finishes downloading, just set the downloaded image as an image.

Here's how you can do it:

 // First let the smaller image download naturally [self.imageView setImageWithURL:self.imageURL]; // Slowly download the larger version of the image SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadWithURL:self.currentPhoto.largeImageURL options:SDWebImageLowPriority progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { if (image) { [self.imageView setImage:image]; } }]; 

Notice how I used the SDWebImageLowPriority parameter. Thus, the image (which should naturally be larger than the first) will be loaded with low priority and should not cancel the first download.

+5
source

Late, but I solved the problem with the following code

 UIImageView * hiddenImageView = [[UIImageView alloc] init]; [hiddenImageView sd_setImageWithURL:thumbUrl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (image) { mImageView.image = image; } if (originalUrl != nil) { [mImageView sd_setImageWithURL:originalUrl placeholderImage:image completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){ if (image) { mImageView.image = image; // optional } }]; } }]; 
+2
source

Load the hidden UIImageView somewhere in the view, and then switch between the two when you're done loading, through:

 [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}]; 
+1
source

Source: https://habr.com/ru/post/1446528/


All Articles