iOS的SDWebImage淡入新形象 [英] iOS SDWebImage fade in new image

查看:437
本文介绍了iOS的SDWebImage淡入新形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直用我的iPhone应用程序SDWebImage来处理所有的图像加载的。我使用的是占位的形象,我想还是交叉淡入淡出的新形象褪色一旦加载。我使用的是成功的块来设定的图像,它是伟大的工作。不管我怎么努力,图像也不会消失,虽然英寸我试着发送动画code回到主线程,但没有帮助。它只是加载瞬间......没有动画。

下面是我的code。有什么想法?

  //加载图像占位符
NSURL * URL = ...
_imageView = [[UIImageView的页头]初始化];
[_imageView setImage:[UIImage的imageNamed:@loading.jpg]];//请求图像
SDWebImageManager *经理= [SDWebImageManager sharedManager]
[经理downloadWithURL:网址
                委托:自我
                 选项​​:0
                 成功:^(*的UIImage图像){                     [UIView的transitionWithView:_imageView
                                       持续时间:3.0
                                        选项​​:UIViewAnimationOptionTransitionCrossDissolve
                                     动画:^ {
                                         [_imageView setImage:图像]。
                                     }完成:NULL];}
失败:无];


解决方案

您可以设置imageView.alpha为0动画块前右,然后在动画块都以动画回imageView.alpha = 1.0;

  //加载图像占位符
NSURL * URL = ...
_imageView = [[UIImageView的页头]初始化];
[_imageView setImage:[UIImage的imageNamed:@loading.jpg]];//请求图像
SDWebImageManager *经理= [SDWebImageManager sharedManager]
[经理downloadWithURL:网址
            委托:自我
             选项​​:0
             成功:^(*的UIImage图像,BOOL缓存){                  imageView.alpha = 0.0;
                 [UIView的transitionWithView:_imageView
                                   持续时间:3.0
                                    选项​​:UIViewAnimationOptionTransitionCrossDissolve
                                 动画:^ {
                                     [_imageView setImage:图像]。
                                      imageView.alpha = 1.0;
                                 }完成:NULL];}
失败:无];

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];

解决方案

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];

这篇关于iOS的SDWebImage淡入新形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆