diff --git a/YYImage/YYAnimatedImageView.h b/YYImage/YYAnimatedImageView.h index e70a654..6c2e9d9 100644 --- a/YYImage/YYAnimatedImageView.h +++ b/YYImage/YYAnimatedImageView.h @@ -80,6 +80,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic) NSUInteger maxBufferSize; +/** + Adds a callback at the end of a loop + */ +@property (nonatomic, copy) void(^loopCompletionBlock)(NSUInteger loopCountRemaining); + @end diff --git a/YYImage/YYAnimatedImageView.m b/YYImage/YYAnimatedImageView.m index 5f2bcb4..7402587 100644 --- a/YYImage/YYAnimatedImageView.m +++ b/YYImage/YYAnimatedImageView.m @@ -498,6 +498,9 @@ - (void)step:(CADisplayLink *)link { [self willChangeValueForKey:@"currentAnimatedImageIndex"]; _curIndex = nextIndex; [self didChangeValueForKey:@"currentAnimatedImageIndex"]; + if (_curIndex + 1 == _totalFrameCount && self.loopCompletionBlock) { + self.loopCompletionBlock(_totalLoop - _curLoop); + } _curFrame = bufferedImage == (id)[NSNull null] ? nil : bufferedImage; if (_curImageHasContentsRect) { _curContentsRect = [image animatedImageContentsRectAtIndex:_curIndex];