From 9e48da8a8a747ab24b162d0361bad422b63c27f0 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 16 Jan 2018 00:15:15 +0800 Subject: [PATCH] Update and remove the deprecated method. Add some documents for un-documented methods --- SDWebImage/UIImage+ForceDecode.h | 12 ++++++++++++ SDWebImage/UIImage+MultiFormat.h | 19 +++++++++++++++++++ SDWebImage/UIImageView+WebCache.h | 28 +++------------------------- SDWebImage/UIImageView+WebCache.m | 11 ----------- SDWebImage/UIView+WebCache.h | 2 +- SDWebImage/UIView+WebCache.m | 6 +++++- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/SDWebImage/UIImage+ForceDecode.h b/SDWebImage/UIImage+ForceDecode.h index e8ef5340..ae85114b 100644 --- a/SDWebImage/UIImage+ForceDecode.h +++ b/SDWebImage/UIImage+ForceDecode.h @@ -10,8 +10,20 @@ @interface UIImage (ForceDecode) +/** + Decompress (force decode before rendering) the provided image + + @param image The image to be decompressed + @return The decompressed image + */ + (nullable UIImage *)sd_decodedImageWithImage:(nullable UIImage *)image; +/** + Decompress and scale down the provided image + + @param image The image to be decompressed + @return The decompressed and scaled down image + */ + (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image; @end diff --git a/SDWebImage/UIImage+MultiFormat.h b/SDWebImage/UIImage+MultiFormat.h index bec411e0..f316fe96 100644 --- a/SDWebImage/UIImage+MultiFormat.h +++ b/SDWebImage/UIImage+MultiFormat.h @@ -11,8 +11,27 @@ @interface UIImage (MultiFormat) +/** + Create and decode a image with the specify image data + + @param data The image data + @return The created image + */ + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data; + +/** + Encode the current image to the data, the image format is unspecified + + @return The encoded data. If can't encode, return nil + */ - (nullable NSData *)sd_imageData; + +/** + Encode the current image to data with the specify image format + + @param imageFormat The specify image format + @return The encoded data. If can't encode, return nil + */ - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat; @end diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index ef2eacfd..7b7d530d 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -154,31 +154,6 @@ progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock; -/** - * Set the imageView `image` with an `url` and custom options. The placeholder image is from previous cached image and will use the provided one instead if the query failed. - * This method was designed to ensure that placeholder and query cache process happened in the same runloop to avoid flashing on cell during two `setImage:` call. But it's really misunderstanding and deprecated. - * This can be done by using `sd_setImageWithURL:` with `SDWebImageQueryDiskSync`. But take care that if the memory cache missed, query disk cache synchronously may reduce the frame rate - * - * The download is asynchronous and cached. - * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param progressBlock A block called while image is downloading - * @note the progress block is executed on a background queue - * @param completedBlock A block called when operation has been completed. This block has no return value - * and takes the requested UIImage as first parameter. In case of error the image parameter - * is nil and the second parameter may contain an NSError. The third parameter is a Boolean - * indicating if the image was retrieved from the local cache or from the network. - * The fourth parameter is the original image url. - * @deprecated consider using `SDWebImageQueryDiskSync` options with `sd_setImageWithURL:` instead - */ -- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url - placeholderImage:(nullable UIImage *)placeholder - options:(SDWebImageOptions)options - progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock - completed:(nullable SDExternalCompletionBlock)completedBlock __deprecated_msg("This method is misunderstanding and deprecated, consider using `SDWebImageQueryDiskSync` options with `sd_setImageWithURL:` instead"); - #if SD_UIKIT #pragma mark - Animation of multiple images @@ -190,6 +165,9 @@ */ - (void)sd_setAnimationImagesWithURLs:(nonnull NSArray *)arrayOfURLs; +/** + * Cancel the current animation images load + */ - (void)sd_cancelCurrentAnimationImagesLoad; #endif diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index aa8ce431..cc9b476d 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -54,17 +54,6 @@ completed:completedBlock]; } -- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url - placeholderImage:(nullable UIImage *)placeholder - options:(SDWebImageOptions)options - progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock - completed:(nullable SDExternalCompletionBlock)completedBlock { - NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url]; - UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromCacheForKey:key]; - - [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock]; -} - #if SD_UIKIT #pragma mark - Animation of multiple images diff --git a/SDWebImage/UIView+WebCache.h b/SDWebImage/UIView+WebCache.h index 941d0f3a..dea29aa9 100644 --- a/SDWebImage/UIView+WebCache.h +++ b/SDWebImage/UIView+WebCache.h @@ -34,7 +34,7 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima * * @note Note that because of the limitations of categories this property can get out of sync if you use setImage: directly. */ -- (nullable NSURL *)sd_imageURL; +@property (nonatomic, strong, readonly, nullable) NSURL *sd_imageURL; /** * The current image loading progress associated to the view. The unit count is the received size and excepted size of download. diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index d4cc8984..c12baeaa 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -32,6 +32,10 @@ static char TAG_ACTIVITY_SHOW; return objc_getAssociatedObject(self, &imageURLKey); } +- (void)setSd_imageURL:(NSURL * _Nullable)sd_imageURL { + objc_setAssociatedObject(self, &imageURLKey, sd_imageURL, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + - (NSProgress *)sd_imageProgress { NSProgress *progress = objc_getAssociatedObject(self, @selector(sd_imageProgress)); if (!progress) { @@ -65,7 +69,7 @@ static char TAG_ACTIVITY_SHOW; context:(nullable NSDictionary *)context { NSString *validOperationKey = operationKey ?: NSStringFromClass([self class]); [self sd_cancelImageLoadOperationWithKey:validOperationKey]; - objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + self.sd_imageURL = url; if (!(options & SDWebImageDelayPlaceholder)) { if ([context valueForKey:SDWebImageInternalSetImageGroupKey]) {