我有一个表视图,它使用 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) 来避免图像位于缓存中后的动画。
提前谢谢了。
而不是 self.view 尝试这个 cell.hotelImage
这会起作用:)
[UIView transitionWithView:cell.hotelImage
duration:1.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{[cell.hotelImage setImage:image];}
completion:NULL];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)