Skip to content

Commit

Permalink
Add an property to YYAnimatedImageView for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
caughtinflux committed Apr 11, 2016
1 parent 51fe3ef commit 6105ed7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions YYWebImage/Image/YYAnimatedImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#import <UIKit/UIKit.h>

@protocol YYAnimatedImage;

NS_ASSUME_NONNULL_BEGIN

/**
Expand Down Expand Up @@ -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


Expand Down
14 changes: 14 additions & 0 deletions YYWebImage/Image/YYAnimatedImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ - (void)setHighlighted:(BOOL)highlighted {
[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;
Expand Down

0 comments on commit 6105ed7

Please sign in to comment.