【问题标题】:AFNetworking - Fade animation on image while scrolling UITableViewAFNetworking - 滚动 UITableView 时在图像上淡化动画
【发布时间】:2012-12-08 02:16:00
【问题描述】:

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

这是我在 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) 来避免动画。

非常感谢。

【问题讨论】:

    标签: uitableview uiimageview afnetworking uianimation


    【解决方案1】:

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

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

    【讨论】:

    • 效果很好。非常感谢!
    猜你喜欢
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多