Tag: ext nload requires INI ade nal return cancel ring
Objective
These three categories are relatively simple, and they are interpreted together.
Body Uiimageview+webcache
This is the classification of Uiimageview, which is designed to load images using Uiimageview.
Let's look at the specific code
1- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL;2 3- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL4Placeholderimage: (Nullable UIImage *) placeholder;5 6- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL7Placeholderimage: (Nullable UIImage *) Placeholder8 options: (sdwebimageoptions) options;9 Ten- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL One Completed: (nullable sdexternalcompletionblock) Completedblock; A -- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL -Placeholderimage: (Nullable UIImage *) Placeholder the Completed: (nullable sdexternalcompletionblock) Completedblock; - -- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL -Placeholderimage: (Nullable UIImage *) Placeholder + options: (sdwebimageoptions) Options - Completed: (nullable sdexternalcompletionblock) Completedblock; + A- (void) Sd_setimagewithurl: (Nullable Nsurl *) URL atPlaceholderimage: (Nullable UIImage *) Placeholder - options: (sdwebimageoptions) Options - Progress: (Nullable Sdwebimagedownloaderprogressblock) Progressblock - Completed: (nullable sdexternalcompletionblock) Completedblock; - -- (void) Sd_setimagewithpreviouscachedimagewithurl: (Nullable Nsurl *) URL inPlaceholderimage: (Nullable UIImage *) Placeholder - options: (sdwebimageoptions) Options to Progress: (Nullable Sdwebimagedownloaderprogressblock) Progressblock +Completed: (nullable sdexternalcompletionblock) Completedblock;
Jumping to the specific implementations of these methods, it is obvious that they eventually call this method of Uiview+webcache (this method is then explained):
-(void) Sd_internalsetimagewithurl: (Nullable Nsurl *) URL *) Placeholder options: ( sdwebimageoptions) Options *) Operationkey setimageblock: (Nullable Sdsetimageblock) Setimageblock Progress: (Nullable Sdwebimagedownloaderprogressblock) Progressblock completed: (Nullable Sdexternalcompletionblock) Completedblock;
There's a little bit of attention below:
Underlined three-mesh operator, which returns the condition itself by default if the first argument after the question mark is not filled in.
So next, there are two ways to interpret this class:
1 /* * 2 * Download An array of images and starts them in an animation loop 3 * 4 * @param arrayofurls An array of Nsurl 5 */ 6 -(void) Sd_setanimationimageswithurls: (nonnull nsarray<nsurl *> *) arrayofurls; 7 8 -(void) sd_cancelcurrentanimationimagesload;
According to the method declaration, we learned that this is an array of frame animation images used to load Uiimageview. We look directly at the concrete implementation of the method:
- (void) Sd_setanimationimageswithurls: (nonnull nsarray<nsurl *> *) Arrayofurls {[Self sd_cancelcurrentanimationimagesload]; __weak __typeof (self) wself=Self ; Nsmutablearray<ID<SDWebImageOperation>> *operationsarray =[[Nsmutablearray alloc] init]; for(Nsurl *logoimageurlincharrayofurls) { ID<SDWebImageOperation> operation = [Sdwebimagemanager.sharedmanager loadimagewithurl:logoimageurl options:0Progress:nil completed:^ (UIImage *image, NSData *data, Nserror *error, Sdimagecachetype CacheType, BOOL finished, NSURL *ImageURL) { if(!wself)return; Dispatch_main_async_safe (^{__strong Uiimageview*sself =wself; [Sself stopanimating]; if(Sself &&image) {Nsmutablearray<uiimage *> *currentimages =[[Sself animationimages] mutablecopy]; if(!currentimages) {Currentimages=[[Nsmutablearray alloc] init]; } [Currentimages Addobject:image]; Sself.animationimages=currentimages; [Sself Setneedslayout]; } [Sself startanimating]; }); }]; [Operationsarray addobject:operation]; } [self Sd_setimageloadoperation:[operationsarray copy] Forkey:@"uiimageviewanimationimages"];}- (void) sd_cancelcurrentanimationimagesload {[Self Sd_cancelimageloadoperationwithkey:@"uiimageviewanimationimages"];}
As we can see, this method iterates through the image URL array and then uses the Sdwebimagemanager method to place each picture loaded into the operation array, and then calls:
[Self sd_setimageloadoperation:[operationsarray copy] forkey:@ "Uiimageviewanimationimages"];
This method is uiview+webcacheoperation, which stores all operations in a dictionary.
Inside this method, we see "Dispatch_main_async_safe"
1 #ifndef Dispatch_main_async_safe2 #defineDispatch_main_async_safe (Block)3 if(strcmp (Dispatch_queue_get_label (Dispatch_current_queue_label), Dispatch_queue_get_label (dispatch_get_main_ Queue ())) = =0) {4 block ();5}Else {6 Dispatch_async (Dispatch_get_main_queue (), block);7 }8 #endif
This is a macro definition in the Sdwebimagecompat class. The goal is to ensure thread safety and to ensure that the code in the block executes in the main thread. When the picture is downloaded, it is updated uiimageview on the main thread.
-(void) sd_cancelcurrentanimationimagesload { [self sd_cancelimageloadoperationwithkey: @ "uiimageviewanimationimages"];}
The last method is to cancel the animationimages operation that is currently being loaded
Sdwebimage Source code Interpretation (iv) Uiimageview+webcache