ibireme / YYImage

Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.
MIT License
1.77k stars 482 forks source link

Notifies the animation end #124

Open animis93 opened 6 years ago

animis93 commented 6 years ago

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

j796160836 commented 6 years ago

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
    }
}];