遇到场景:首先直播需要展示 礼物(会动的礼物)
解决:按之前的考虑是 加载 gif , 但是gif 会产生锯齿导致礼物不好看,最后我们想到了webp , 我们将 UI 设计好的 png 几个帧数 合成了webp 格式。
pod 'YYWebImage', '~> 1.0.5'
跟着执行
pod 'YYImage/WebP'
其实WebP 有两种,一种是静态,一种是动态(类似gif 很多张合成一个会动的图)
- 这个是静态的webp
YYAnimatedImageView *imgView = [[YYAnimatedImageView alloc] init]; imgView.frame = CGRectMake(10.f, 80.f, width, width); imgView.backgroundColor = [UIColor purpleColor]; [self.view addSubview:imgView]; NSURL *url = [NSURL URLWithString:@"http://xx/app/test.webp"]; [imgView yy_setImageWithURL:url placeholder:nil];
- 这加载 动态的webp
YYAnimatedImageView *imgView2 = [[YYAnimatedImageView alloc] init]; imgView2.frame = CGRectMake(CGRectGetMaxX(imgView.frame) + 10.f, CGRectGetMinY(imgView.frame), width, width); imgView2.backgroundColor = [UIColor purpleColor]; [self.view addSubview:imgView2]; NSURL *url2 = [NSURL URLWithString:@"http://pia2njyxv.bkt.clouddn.com/out.webp"]; [imgView2 yy_setImageWithURL:url2 placeholder:nil];
- 这个是加载gif (为了对比记载一个gif 看看)
YYAnimatedImageView *imgView3 = [[YYAnimatedImageView alloc] init]; imgView3.frame = CGRectMake(10.f, CGRectGetMaxY(imgView.frame) + 20.f, width, width); imgView3.backgroundColor = [UIColor purpleColor]; [self.view addSubview:imgView3]; NSURL *url3 = [NSURL URLWithString:@"http://xx/pre/gifts/gift_send_5_.gif"]; [imgView3 yy_setImageWithURL:url3 placeholder:nil];
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/216080.html原文链接:https://javaforall.net
