iOS SDWebImage fade in new image

后端 未结 8 1484
北海茫月
北海茫月 2021-01-31 06:36

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.

8条回答
  •  灰色年华
    2021-01-31 07:01

    You could set the imageView.alpha to 0 right before the animation block, then in the animation block have it animate back to imageView.alpha = 1.0;

    // 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, BOOL cached) {
    
                      imageView.alpha = 0.0;
                     [UIView transitionWithView:_imageView
                                       duration:3.0
                                        options:UIViewAnimationOptionTransitionCrossDissolve
                                     animations:^{
                                         [_imageView setImage:image];
                                          imageView.alpha = 1.0;
                                     } completion:NULL];
    
    }
    failure:nil];
    

提交回复
热议问题