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

相关推荐
GentleDevin1 天前
Mac 常用快捷键速查表
macos
GOU921 天前
5101实验
网络·macos
柯儿的天空1 天前
【OpenClaw 全面解析:从零到精通】第 005 篇:OpenClaw 在 macOS 上的安装与部署实战
人工智能·macos·自然语言处理·ai作画
2501_915909061 天前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
@大迁世界1 天前
液态玻璃屏正在侵蚀你的电池
macos·ios·objective-c·cocoa
liangshanbo12151 天前
[特殊字符] macOS 上的 zoxide:智能目录跳转终极指南
macos·策略模式
pop_xiaoli1 天前
【iOS】类与对象底层
macos·ios·objective-c·cocoa·xcode
sp42a1 天前
NativeScript iOS 平台开发技巧
ios·nativescript·app 开发
2501_915921431 天前
常用iOS性能测试工具大全及使用指南
android·测试工具·ios·小程序·uni-app·cocoa·iphone
for_ever_love__1 天前
Objecgtive-C学习实例对象,类对象, 元类对象与 isa指针
c语言·学习·ios