优化图片加载

写了个类别, 让图片加载完毕不会很突兀地就这么出来

- (void)NA_setWithImageURL:(NSString *)imageURL
           placeholder:(UIImage *)placeholder completion:(void (^)(UIImage * image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL))completion{

[self sd_setImageWithURL:[NSURL URLWithString:imageURL]
        placeholderImage:placeholder
               completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                   
                   if (image && cacheType == SDImageCacheTypeNone) {
                       
                       CATransition *transition = [CATransition animation];
                       transition.type = kCATransitionFade;
                       transition.duration = .3;
                       transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
                       [self.layer addAnimation:transition forKey:nil];
                       
                   }
                   
                   completion(image, error, cacheType, imageURL);
               }];
}

你可能感兴趣的:(优化图片加载)