Sdwebimage, some methods for loading images by third parties asynchronously
1. First add third-party files (sdwebimage) to the project
2. Modify the Arc
3. Add a ImageView to the Viewcontrol to add a tap tap gesture to display the downloaded image
A. sd_setimagewithurl
Introducing Header Files
#import "uiimageview+webcache.h"
-(Ibaction) Tap: (UITapGestureRecognizer *) Sender { NSLog (@ "%s", __ function__); // loading pictures asynchronously sd_setimagewithurl: [nsurl urlwithstring:@ "http://img3.douban.com/view/photo/photo/ Public/p1910869260.jpg"] placeholderimage:nil options:0];
}
B. Sdwebimagemanager
Introducing Header Files
#import "SDWebImageManager.h"
-(Ibaction) Tap: (UITapGestureRecognizer *) Sender {NSLog (@"%s", __function__); //Loading Pictures asynchronously Sdwebimagemanager*manager =[Sdwebimagemanager Sharedmanager]; [Manager Downloadimagewithurl: [Nsurl urlwithstring:@"http://img3.douban.com/view/photo/photo/public/p2151245053.jpg"] Options:0progress:^(Nsinteger receivedsize, Nsinteger expectedsize) {} Completed:^ (UIImage *image, Nserror *error, Sdimagecachetype CacheType, BOOL finished, Nsurl *ImageURL) { if(finished) {Self.imageView.image=image; } }];}
c. sdwebimagedownloader Standalone use of asynchronous picture download
Introducing Header Files
#import "SDWebImageDownloader.h"
Sdwebimagedownloader * Downloader = [Sdwebimagedownloader Shareddownloader]; [Downloader Downloadimagewithurl : [nsurl urlwithstring: @ " http://img4.douban.com/view/photo/photo/public/p1940511226.jpg " Span style= "color: #800000;" > "] options:0 progress:^ (Nsinteger Receivedsize, Nsinteger expectedsize) {} Completed: ^ (UIImage *image, NSData *data, Nserror *error, BOOL finished) { if (finished) { Self.imageView.image = image; } }];
d. Sdimagecache
Cache Pictures , in Key value to mark the picture , Extract Pictures , The next time you want to use the image can be quickly extracted
Introducing Header Files
#import "uiimageview+webcache.h"
-(Ibaction) Tap: (UITapGestureRecognizer *) Sender {NSLog (@"%s", __function__); //Sdimagecache Single Case Method[[SdimagecacheSharedimagecache] Storeimage:[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://img3.doubanio.com/view/photo/photo/public/p522751329.jpg"]] Forkey:@"MySpace"]; //Querydiskcacheforkey, looking for cached pictures by key value[[Sdimagecache Sharedimagecache]Querydiskcacheforkey:@"MySpace"done:^ (UIImage *image, Sdimagecachetype cachetype) {Self.imageView.image=image; }];}you don't need to download the image again, you can extract it directly from the cache.-(Ibaction) Other: (UITapGestureRecognizer *) Sender {NSLog (@" Other"); [[Sdimagecache Sharedimagecache] querydiskcacheforkey:@"MySpace"done:^ (UIImage *image, Sdimagecachetype cachetype) {Self.otherImage.image=image; }];}
Click ImageView to cache the image cache with the "MySpace" flag and display it, then click on another view to extract the image from the cache with the "MySpace" logo, without having to download it again to quickly show it.
Sdwebimage, some methods for loading images by third parties asynchronously