GitHub - joywt/ImageLazyLoad: 列表图片加载优化
实例采用的动画效果是简单的渐显,如需修改动画效果可修改 ImageLazyLoadViewController.m文件 中的 - (void)setupCell:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法,源代码如下:
```
if (cellImageView && targetURL && ![[cellImageView sd_imageURL] isEqual:targetURL]) {
cellImageView.alpha = 0.0;
SDWebImageManager *manager = [SDWebImageManager sharedManager];
CGRect cellFrame = [self.tableView rectForRowAtIndexPath:indexPath];
BOOL shouldLoadImage = YES;
if (self.targetRect && !CGRectIntersectsRect([self.targetRect CGRectValue], cellFrame)) {
SDImageCache *cache = [manager imageCache];
NSString *key = [manager cacheKeyForURL:targetURL];
if (![cache imageFromMemoryCacheForKey:key]) {
shouldLoadImage = NO;
}
}
if (shouldLoadImage) {
[cellImageView sd_setImageWithURL:targetURL placeholderImage:self.defaultImage options:SDWebImageHandleCookies completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if ([imageURL isEqual:targetURL]) {
[UIView animateWithDuration:0.3 animations:^{
cellImageView.alpha = 1.0;
}];
}
}];
}
}
```