AFNetworking-滚动UITableView时淡出图像上的动画 [英] AFNetworking - Fade animation on image while scrolling UITableView

查看:89
本文介绍了AFNetworking-滚动UITableView时淡出图像上的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,该表视图使用来自AFNetworking的延迟加载和占位符图像来显示图像。我正在尝试找到一种在加载时从占位符淡入图像的方法。我的代码在这里工作,但是如果在滚动表时加载了图像,则一切看起来都很奇怪,并且表停止了滚动。水平滚动器也会发生同样的事情,并且效果相同。

I have a Table View which displays images using lazy loading from AFNetworking with a placeholder image. I'm trying to accomplish a way to fade from the placeholder to the image when it's loaded. My code here works, but if an image loads while scrolling the table, everything looks odd and the table stops scrolling. Same thing happens to a Horizontal scroller with the same effect.

这是我在cellForRowAtIndexPath内部使用的代码

Here's the code I'm using inside cellForRowAtIndexPath

    [cell.hotelImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:hotelImageUrl]]
                  placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                           success:^(NSURLRequest *request , NSHTTPURLResponse *response , UIImage *image ){

                               if (request) {
                                   //Fade animation
                                   [UIView transitionWithView:self.view
                                                     duration:1.0f
                                                      options:UIViewAnimationOptionTransitionCrossDissolve
                                                   animations:^{
                                                       [cell.hotelImage setImage:image];
                                                   } completion:NULL];

                               }


                           }
                           failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){

                           }
 ];

一旦图像在缓存中,我正在使用if(request)避免动画。

I'm using the if(request) to avoid the animation once the image is in the cache.

非常感谢。

推荐答案

而不是self.view试试这个cell.hotelImage
这将起作用:)

instead of self.view try this cell.hotelImage this will work :)

 [UIView transitionWithView:cell.hotelImage
   duration:1.0f
   options:UIViewAnimationOptionTransitionCrossDissolve
   animations:^{[cell.hotelImage setImage:image];} 
 completion:NULL];

这篇关于AFNetworking-滚动UITableView时淡出图像上的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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