ibireme/YYImage

Notifies the animation end

animis93 opened this issue · 1 comments

Could you add a method to notify when the animation ends?

You can use KVO for the currentAnimatedImageIndex and check it with animatedImageFrameCount.
Here is the sample code with KVOController:

__weak typeof(self) weakSelf = self;

[self.KVOController observe:self.myYYAnimatedImageView keyPath:@"currentAnimatedImageIndex" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew block:^(id  _Nullable observer, YYAnimatedImageView *imageView, NSDictionary *change) {
    YYImage *image = (YYImage *) imageView.image;
    NSInteger frameNum = [change[@"new"] integerValue];
    if (frameNum == image.animatedImageFrameCount - 1) {
        [weakSelf.KVOController unobserve:imageView];
        // Do something you want with myYYAnimatedImageView
    }
}];