Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一张图片需要用在不同的地方,进行不同的处理,想同时缓存这些不同的处理 #128

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions Demo/YYWebImageDemo/YYWebImageExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ - (void)setImageURL:(NSURL *)url {
}
}
transform:nil
completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
if (stage == YYWebImageStageFinished) {
_self.progressLayer.hidden = YES;
[_self.indicator stopAnimating];
_self.indicator.hidden = YES;
if (!image) _self.label.hidden = NO;
}
}];
transformKey:nil
completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
if (stage == YYWebImageStageFinished) {
_self.progressLayer.hidden = YES;
[_self.indicator stopAnimating];
_self.indicator.hidden = YES;
if (!image) _self.label.hidden = NO;
}
}];
}

- (void)prepareForReuse {
Expand Down
30 changes: 17 additions & 13 deletions YYWebImage/Categories/CALayer+YYWebImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,41 @@ NS_ASSUME_NONNULL_BEGIN
/**
Set the view's `image` with a specified URL.

@param imageURL The image url (remote or local file path).
@param placeholder The image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param completion The block invoked (on main thread) when image request completed.
@param imageURL The image url (remote or local file path).
@param placeholder The image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param transformKey 转换key,链接相同但key不同会有不同的缓存
@param completion The block invoked (on main thread) when image request completed.
*/
- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
placeholder:(nullable UIImage *)placeholder
options:(YYWebImageOptions)options
progress:(nullable YYWebImageProgressBlock)progress
transform:(nullable YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(nullable YYWebImageCompletionBlock)completion;

/**
Set the view's `image` with a specified URL.

@param imageURL The image url (remote or local file path).
@param placeholder he image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param manager The manager to create image request operation.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param completion The block invoked (on main thread) when image request completed.
@param imageURL The image url (remote or local file path).
@param placeholder he image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param manager The manager to create image request operation.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param transformKey 转换key,链接相同但key不同会有不同的缓存
@param completion The block invoked (on main thread) when image request completed.
*/
- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
placeholder:(nullable UIImage *)placeholder
options:(YYWebImageOptions)options
manager:(nullable YYWebImageManager *)manager
progress:(nullable YYWebImageProgressBlock)progress
transform:(nullable YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(nullable YYWebImageCompletionBlock)completion;

/**
Expand Down
12 changes: 10 additions & 2 deletions YYWebImage/Categories/CALayer+YYWebImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ - (void)setYy_imageURL:(NSURL *)imageURL {
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:nil];
}

Expand All @@ -45,6 +46,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL placeholder:(UIImage *)placeholder
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:nil];
}

Expand All @@ -55,6 +57,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL options:(YYWebImageOptions)options
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:nil];
}

Expand All @@ -68,6 +71,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:completion];
}

Expand All @@ -76,13 +80,15 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
options:(YYWebImageOptions)options
progress:(YYWebImageProgressBlock)progress
transform:(YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(YYWebImageCompletionBlock)completion {
[self yy_setImageWithURL:imageURL
placeholder:placeholder
options:options
manager:nil
progress:progress
transform:transform
transformKey:transformKey
completion:completion];
}

Expand All @@ -92,6 +98,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
manager:(YYWebImageManager *)manager
progress:(YYWebImageProgressBlock)progress
transform:(YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(YYWebImageCompletionBlock)completion {
if ([imageURL isKindOfClass:[NSString class]]) imageURL = [NSURL URLWithString:(id)imageURL];
manager = manager ? manager : [YYWebImageManager sharedManager];
Expand Down Expand Up @@ -122,7 +129,8 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
if (manager.cache &&
!(options & YYWebImageOptionUseNSURLCache) &&
!(options & YYWebImageOptionRefreshImageCache)) {
imageFromMemory = [manager.cache getImageForKey:[manager cacheKeyForURL:imageURL] withType:YYImageCacheTypeMemory];
imageFromMemory = [manager.cache getImageForKey:[manager cacheKeyForURL:imageURL transformKey:transformKey
] withType:YYImageCacheTypeMemory];
}
if (imageFromMemory) {
if (!(options & YYWebImageOptionAvoidSetImage)) {
Expand Down Expand Up @@ -173,7 +181,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
});
};

newSentinel = [setter setOperationWithSentinel:sentinel url:imageURL options:options manager:manager progress:_progress transform:transform completion:_completion];
newSentinel = [setter setOperationWithSentinel:sentinel url:imageURL options:options manager:manager progress:_progress transform:transform transformKey:transformKey completion:_completion];
weakSetter = setter;
});

Expand Down
30 changes: 17 additions & 13 deletions YYWebImage/Categories/MKAnnotationView+YYWebImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,41 @@ NS_ASSUME_NONNULL_BEGIN
/**
Set the view's `image` with a specified URL.

@param imageURL The image url (remote or local file path).
@param placeholder The image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param completion The block invoked (on main thread) when image request completed.
@param imageURL The image url (remote or local file path).
@param placeholder The image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param transformKey 转换key,链接相同但key不同会有不同的缓存
@param completion The block invoked (on main thread) when image request completed.
*/
- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
placeholder:(nullable UIImage *)placeholder
options:(YYWebImageOptions)options
progress:(nullable YYWebImageProgressBlock)progress
transform:(nullable YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(nullable YYWebImageCompletionBlock)completion;

/**
Set the view's `image` with a specified URL.

@param imageURL The image url (remote or local file path).
@param placeholder he image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param manager The manager to create image request operation.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param completion The block invoked (on main thread) when image request completed.
@param imageURL The image url (remote or local file path).
@param placeholder he image to be set initially, until the image request finishes.
@param options The options to use when request the image.
@param manager The manager to create image request operation.
@param progress The block invoked (on main thread) during image request.
@param transform The block invoked (on background thread) to do additional image process.
@param transformKey 转换key,链接相同但key不同会有不同的缓存
@param completion The block invoked (on main thread) when image request completed.
*/
- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
placeholder:(nullable UIImage *)placeholder
options:(YYWebImageOptions)options
manager:(nullable YYWebImageManager *)manager
progress:(nullable YYWebImageProgressBlock)progress
transform:(nullable YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(nullable YYWebImageCompletionBlock)completion;

/**
Expand Down
11 changes: 9 additions & 2 deletions YYWebImage/Categories/MKAnnotationView+YYWebImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ - (void)setYy_imageURL:(NSURL *)imageURL {
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:nil];
}

Expand All @@ -45,6 +46,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL placeholder:(UIImage *)placeholder
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:nil];
}

Expand All @@ -55,6 +57,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL options:(YYWebImageOptions)options
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:nil];
}

Expand All @@ -68,6 +71,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
manager:nil
progress:nil
transform:nil
transformKey:nil
completion:completion];
}

Expand All @@ -76,13 +80,15 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
options:(YYWebImageOptions)options
progress:(YYWebImageProgressBlock)progress
transform:(YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(YYWebImageCompletionBlock)completion {
[self yy_setImageWithURL:imageURL
placeholder:placeholder
options:options
manager:nil
progress:progress
transform:transform
transformKey:transformKey
completion:completion];
}

Expand All @@ -92,6 +98,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
manager:(YYWebImageManager *)manager
progress:(YYWebImageProgressBlock)progress
transform:(YYWebImageTransformBlock)transform
transformKey:(nullable NSString *)transformKey
completion:(YYWebImageCompletionBlock)completion {
if ([imageURL isKindOfClass:[NSString class]]) imageURL = [NSURL URLWithString:(id)imageURL];
manager = manager ? manager : [YYWebImageManager sharedManager];
Expand Down Expand Up @@ -122,7 +129,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
if (manager.cache &&
!(options & YYWebImageOptionUseNSURLCache) &&
!(options & YYWebImageOptionRefreshImageCache)) {
imageFromMemory = [manager.cache getImageForKey:[manager cacheKeyForURL:imageURL] withType:YYImageCacheTypeMemory];
imageFromMemory = [manager.cache getImageForKey:[manager cacheKeyForURL:imageURL transformKey:transformKey] withType:YYImageCacheTypeMemory];
}
if (imageFromMemory) {
if (!(options & YYWebImageOptionAvoidSetImage)) {
Expand Down Expand Up @@ -173,7 +180,7 @@ - (void)yy_setImageWithURL:(NSURL *)imageURL
});
};

newSentinel = [setter setOperationWithSentinel:sentinel url:imageURL options:options manager:manager progress:_progress transform:transform completion:_completion];
newSentinel = [setter setOperationWithSentinel:sentinel url:imageURL options:options manager:manager progress:_progress transform:transform transformKey:transformKey completion:_completion];
weakSetter = setter;
});
});
Expand Down