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

查看:39
本文介绍了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.

非常感谢.

推荐答案

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

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天全站免登陆