iOS加载WebP

iOS加载WebP遇到场景 首先直播需要展示礼物 会动的礼物 解决 按之前的考虑是加载 gif 但是 gif 会产生锯齿导致礼物不好看 最后我们想到了 webp 我们将 UI 设计好的 png 几个帧数合成了 webp 格式 加载 webp 我使用的是 YYWebImage 首先加载执行 pod YYWebImage amp amp gt 1 0 5 跟着执行 pod YYImage Web

遇到场景:首先直播需要展示 礼物(会动的礼物)

解决:按之前的考虑是 加载 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

(0)
上一篇 2026年3月18日 下午12:36
下一篇 2026年3月18日 下午12:36


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号