使用YYAnimatedImageView加载GIF图,并且可以控制只播放一次


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM