iOS 14 YYAnimatedImageView加载图片失败处理

升级到iOS14,之前使用的YYimage框架全部不能正常显示图片,当然动态图正常显示,静态图无法显示;

原因是:14.0 系统调用了下面方法,YYAnimatedImageView没有正确处理

-(void)displayLayer:(CALayer )layer;

1

可以用以下方式处理:

方式一:

更改YYimage源码,在YYAnimationImageView.m中

  • (void)displayLayer:(CALayer *)layer {

if (_curFrame) {

layer.contents = (__bridge id)_curFrame.CGImage;

} else {

if (@available(iOS 14.0, *)) {

super displayLayer:layer\]; } } } 方式二: 不更改YYimage源码,以防之后作者升级,使用Hook的技术处理 + (void)load { Method a = class_getInstanceMethod(self, @selector(displayLayer:)); Method b = class_getInstanceMethod(self, @selector(swizzing_displayLayer:)); method_exchangeImplementations(a, b); } - (void)swizzing_displayLayer:(CALayer \*)layer { //通过变量名称获取类中的实例成员变量 Ivar ivar = class_getInstanceVariable(self.class, "_curFrame"); UIImage \*_curFrame = object_getIvar(self, ivar); if (_curFrame) { layer.contents = (__bridge id)_curFrame.CGImage; } else { if (@available(iOS 14.0, \*)) { \[super displayLayer:layer\]; } } }

相关推荐
徐同保20 小时前
通过ip访问nginx的服务时,被第一个server重定向了,通过设置default_server解决这个问题
ios·iphone
皮卡车厘子20 小时前
Mac 挂载目录
macos
良逍Ai出海1 天前
在 Windows & macOS 上安装 Claude Code,并使用第三方 Key 的完整教程
windows·macos
热爱生活的五柒1 天前
linux/mac/wsl如何使用claude code,并配置免费的硅基流动API?(官方的需要付费订阅)
linux·运维·macos
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
胖胖大王叫我来巡山1 天前
mac本地安装DataEase桌面版
macos
奋斗者1号1 天前
OpenClaw 部署方式对比:云端、WSL、Mac 本机、Ubuntu 虚拟机(2026年2月最新主流实践)
linux·ubuntu·macos
玉梅小洋1 天前
Android SDK 安装指南(MacOS 和 Windows)
android·windows·macos·sdk
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
胖胖大王叫我来巡山1 天前
Mac通过源码安装部署SQLBOT
macos