IOS SDWebImage Cross Fade Effect UITableViewCell

Here's how I successfully use SDWebImageManager to load images:

- (void) downloadThumbnails:(NSURL *) finalUrl { SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadWithURL:finalUrl options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { if (image) { self.thumbnailURL = [finalUrl absoluteString]; } }]; } - (UIImage*)thumbnail { if (!self.thumbnailURL) return nil; return [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:self.thumbnailURL]; } 

How can I change to have a cross fading effect? The Cross Fade effect is one that makes displaying images slow, like the TechCrunch iOS app. Thanks!

UPDATE: If I can do anything else to have a cross-fade effect (other than SDWebImage) in a uitableview cell, than you can write it back.

UPDATE: I received several responses after my last update, and I can partially solve the problem. Using transitionWithView, as in the answer below, it works and cross fades as I want, BUT, since I use a table controller that loads more records, when it touches the bottom, it updates all cells once before a new record block is How can I prevent this behavior?

+4
source share
3 answers

It looks like you are using SDWebImageManager in another file, which is not necessarily the UITableViewController class. You can use transitionWithView, but not with SDWebImageManager directly, if it's in another class.

But in the table view controller class, in which you use cellForRowAtIndexPath and associate the image with the View UITableViewCell image, you can use transitionView as shown below:

 [UIView transitionWithView:cell.(Your Image View) duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ cell.(Your ImageView).image = [(how ever you are calling it)]; } completion:^(BOOL finished) { // Optionally you can do anything after the completion }]; 

Hope this helps!

+4
source

You can use the UIView transitionWithView:duration:options:animations:completion: method to cross-decompose an image from an old image to a new one, for example:

 [UIView transitionWithView:imageView duration:0.4 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ // Set the new image // Since its done in the animation block, the change will be animated imageView.image = newImage; } completion:^(BOOL finished) { // Do whatever when the animation is finished }]; 

Just use this code in your completed block, where you usually set the image in imageView

+1
source

refer to the interface definition:

 - (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock; 

there are several values ​​for SDImageOptions, and I think this is what you expected:

 /** * This flag enables progressive download, the image is displayed progressively during download as a browser would do. * By default, the image is only displayed once completely downloaded. */ SDWebImageProgressiveDownload = 1 << 3 
-one
source

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


All Articles