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

相关推荐
咕噜签名分发冰淇淋2 小时前
内测分发是什么?
ios
2501_916007476 小时前
Transporter App 使用全流程详解:iOS 应用 ipa 上传工具、 uni-app 应用发布指南
android·ios·小程序·https·uni-app·iphone·webview
脚踏实地的大梦想家7 小时前
【Docker】P2 Docker环境构建准备:MacOS 与 Linux
linux·macos·docker
白玉cfc7 小时前
【OC】单例模式
开发语言·ios·单例模式·objective-c
Digitally9 小时前
比较 iPhone:全面比较 iPhone 17 系列
android·ios·iphone
dyxal10 小时前
使用tree命令导出文件夹/文件的目录树( Windows 和 macOS)
windows·macos·策略模式
2501_9159090613 小时前
HTTPS 错误解析,常见 HTTPS 抓包失败、443 端口错误与 iOS 抓包调试全攻略
android·网络协议·ios·小程序·https·uni-app·iphone
心灵宝贝21 小时前
Kite Compositor for Mac v2.1.2 安装教程|DMG文件安装步骤(Mac用户必看)
macos
他们都不看好你,偏偏你最不争气1 天前
【iOS】UIViewController
开发语言·macos·ios·objective-c·cocoa
李游Leo1 天前
Rust 开发环境安装与 crates.io 国内源配置(Windows / macOS / Linux 全流程)
windows·macos·rust