Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS SDWebImage fade in new image

I've been using SDWebImage on my iPhone app to handle all of the image loading. I am using a placeholder image, and I want to crossfade or fade in the new image once it loads. I am using a success block to set the image, and it is working great. No matter what I try, the image will not fade in though. I've tried sending the animation code back to the main thread, but that didn't help either. It just loads instantly... No animation.

Here is my code. Any thoughts?

// load placeholder image
NSURL *url = ...
_imageView = [[UIImageView alloc] init];
[_imageView setImage:[UIImage imageNamed:@"loading.jpg"]];

// request image
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:url
                delegate:self
                 options:0
                 success:^(UIImage *image) {

                     [UIView transitionWithView:_imageView
                                       duration:3.0
                                        options:UIViewAnimationOptionTransitionCrossDissolve
                                     animations:^{
                                         [_imageView setImage:image];
                                     } completion:NULL];

}
failure:nil];
like image 833
nothappybob Avatar asked Aug 08 '12 16:08

nothappybob


1 Answers

Here is the code which help me out and working great.

photoImageView.sd_imageTransition = .fade
photoImageView.sd_setImage(with: URL(string: imageUrl), completed: nil)
like image 50
Chetan Avatar answered Sep 19 '22 13:09

Chetan