项目优化中使用GIF循环播放,然后整一个定时2s,到时间就跳转,这样有问题,然后优化代码,我使用的是YYAnimatedImageView这个类,然后引用过FLAnimatedImage这个第三方,发现有动画执行很慢,类似卡顿现象,才决定继续使用YYAnimatedImageView
具体有优化内容:
1、引入pod 'YYKit' ,'~>1.0.9'
2.初始化YYAnimatedImageView
YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init];
imageView.backgroundColor = [UIColor whiteColor];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
3、加载网络GIF图片
[imageView yy_setImageWithURL:[NSURL URLWithString:@"gif图url链接"] placeholder:[UIImage imageNamed:@"default"]];
4、通过RAC或者自己写观察者,观察currentAnimatedImageIndex播放到什么位置,如果播放到最后一张图,则停止播放
[RACObserve(imageView, currentAnimatedImageIndex) subscribeNext:^(id _Nullable x) {
if ([x integerValue] == self.loadingImageView.animationImages.count) {
[_imageView stopAnimating];
}
}];
网友评论