From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001
From: 单军华
Date: Wed, 11 Jul 2018 10:47:42 +0800
Subject: [PATCH] 首次上传

---
 screendisplay/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m |   70 +++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/screendisplay/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m b/screendisplay/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m
new file mode 100644
index 0000000..19d8b56
--- /dev/null
+++ b/screendisplay/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the SDWebImage package.
+ * (c) Olivier Poitrey <rs@dailymotion.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+#import "UIView+WebCacheOperation.h"
+#import "objc/runtime.h"
+
+static char loadOperationKey;
+
+// key is copy, value is weak because operation instance is retained by SDWebImageManager's runningOperations property
+// we should use lock to keep thread-safe because these method may not be acessed from main queue
+typedef NSMapTable<NSString *, id<SDWebImageOperation>> SDOperationsDictionary;
+
+@implementation UIView (WebCacheOperation)
+
+- (SDOperationsDictionary *)sd_operationDictionary {
+    @synchronized(self) {
+        SDOperationsDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
+        if (operations) {
+            return operations;
+        }
+        operations = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsWeakMemory capacity:0];
+        objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+        return operations;
+    }
+}
+
+- (void)sd_setImageLoadOperation:(nullable id<SDWebImageOperation>)operation forKey:(nullable NSString *)key {
+    if (key) {
+        [self sd_cancelImageLoadOperationWithKey:key];
+        if (operation) {
+            SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
+            @synchronized (self) {
+                [operationDictionary setObject:operation forKey:key];
+            }
+        }
+    }
+}
+
+- (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key {
+    // Cancel in progress downloader from queue
+    SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
+    id<SDWebImageOperation> operation;
+    @synchronized (self) {
+        operation = [operationDictionary objectForKey:key];
+    }
+    if (operation) {
+        if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]){
+            [operation cancel];
+        }
+        @synchronized (self) {
+            [operationDictionary removeObjectForKey:key];
+        }
+    }
+}
+
+- (void)sd_removeImageLoadOperationWithKey:(nullable NSString *)key {
+    if (key) {
+        SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
+        @synchronized (self) {
+            [operationDictionary removeObjectForKey:key];
+        }
+    }
+}
+
+@end

--
Gitblit v1.8.0