Selaa lähdekoodia

Add an property to YYAnimatedImageView for convenience

Aditya KD 9 vuotta sitten
vanhempi
commit
6105ed7770
2 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 8 0
      YYWebImage/Image/YYAnimatedImageView.h
  2. 14 0
      YYWebImage/Image/YYAnimatedImageView.m

+ 8 - 0
YYWebImage/Image/YYAnimatedImageView.h

@@ -11,6 +11,8 @@
 
 #import <UIKit/UIKit.h>
 
+@protocol YYAnimatedImage;
+
 NS_ASSUME_NONNULL_BEGIN
 
 /**
@@ -80,6 +82,12 @@ NS_ASSUME_NONNULL_BEGIN
  */
 @property (nonatomic) NSUInteger maxBufferSize;
 
+/**
+ *  A convenience accessor for the getting the animated image that the image view is currently displaying
+ *  If the `image` property does not contain an animated image, this property returns nil.
+ */
+@property (nonatomic, strong, nullable) UIImage<YYAnimatedImage> *animatedImage;
+
 @end
 
 

+ 14 - 0
YYWebImage/Image/YYAnimatedImageView.m

@@ -301,6 +301,20 @@ typedef NS_ENUM(NSUInteger, YYAnimatedImageType) {
     [self imageChanged];
 }
 
+- (void)setAnimatedImage:(UIImage<YYAnimatedImage> *)animatedImage {
+    if (self.image == animatedImage) {
+        return;
+    }
+    [self setImage:animatedImage withType:YYAnimatedImageTypeImage];
+}
+
+- (UIImage<YYAnimatedImage> *)animatedImage {
+    if (![self.image conformsToProtocol:@protocol(YYAnimatedImage)]) {
+        return nil;
+    }
+    return (UIImage<YYAnimatedImage> *)self.image;
+}
+
 - (id)imageForType:(YYAnimatedImageType)type {
     switch (type) {
         case YYAnimatedImageTypeNone: return nil;