AFNetworking - Fade animation on image while scrolling UITableView

纵然是瞬间 提交于 2019-12-21 04:05:00

问题


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.

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){

                           }
 ];

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

Many thanks in advance.


回答1:


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


来源:https://stackoverflow.com/questions/13974226/afnetworking-fade-animation-on-image-while-scrolling-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!