1.初始化YYAnimatedImageView
YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init];
imageView.backgroundColor = [UIColor whiteColor];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
2.加載網絡GIF圖片
[imageView yy_setImageWithURL:[NSURL URLWithString:@"gif圖url鏈接"] placeholder:[UIImage imageNamed:@"default"]];
3.通過RAC或者自己寫觀察者,觀察currentAnimatedImageIndex播放到什么位置,如果播放到最后一張圖,則停止播放
[RACObserve(imageView, currentAnimatedImageIndex) subscribeNext:^(id _Nullable x) {
if ([x integerValue] == imageView.animationImages.count) {
[_imageView stopAnimating];
}
}];