Reputation: 538
So before anything else, I found this:
SDWebImage process images before caching
which kind of helps but I really want to use SDWebImage
, is there a way to process the images via a method outside of the class before completion?
To my understanding, the completion block in
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock
is run after the image is placed. I would like to run a method before the loaded image is placed.
Is there an easy way to do this?
thank you,
Upvotes: 3
Views: 1620
Reputation: 538
reposting my answer from: SDWebImage process images before caching
SDWebImage developer Olivier Poitrey answered this question for me here.
You have to implement the SDWebImageManagerDelegate protocol and then set it as the shared manager's delegate like this:
SDWebImageManager.sharedManager.delegate = self;
using the imageManager:transformDownloadedImage:withURL: instance method. More information.
Worked perfectly for me.
Upvotes: 2
Reputation: 437592
Two options:
Write your own routine that would Use Asynchronous Image Caching Independently, process the image, and then set the image view's image
property. There are interesting permutations you'd have to worry about (e.g. if cell has been reused before the download has finished, you'd want to cancel the prior image download for that image view), so you need to be careful, but it's not too bad.
Probably easier, though, would be to write your own UIImageView
category that is like the existing one for SDWebImage
(UIImageView+WebCache.m
), but introduce your own permutation of setImageWithURL
which is just like the original, but offers a pre-process completion block, too.
I'd probably lean towards the latter, but both would work perfectly well
Upvotes: 0