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;

}

}

}

相关推荐
末代iOS程序员华仔7 小时前
iOS上架海外工具类应用合规指南:避免封号与下架风险
flutter·ios·swift
寒水馨7 小时前
macOS下载、安装uv-0.12.0(附安装包uv-aarch64-apple-darwin.tar.gz)
python·macos·rust·项目管理·包管理器·astral·pip替代
寒水馨9 小时前
macOS下载、安装protobuf-v35.1(附安装包protoc-35.1-osx-universal_binary.zip)
macos·google·grpc·序列化·protobuf·protoc·数据交换
寒水馨9 小时前
macOS下载、安装ripgrep-15.2.0(附安装包ripgrep-15.2.0-aarch64-apple-darwin.tar.gz)
macos·正则表达式·rust·ripgrep·rg·命令行搜索·代码搜索
末代iOS程序员华仔9 小时前
Flutter 开发 iOS App 上架全流程与常见问题分析
flutter·ios
末代iOS程序员华仔9 小时前
Flutter开发iOS海外工具类应用上架合规指南与风险规避
flutter·ios
AI云海1 天前
iOS 多 Target 打包、UAT/生产测试与上架 App Store 全流程指南
ios
阿里超级工程师1 天前
最新快速申请ios打包证书和profile文件步骤
ios·打包证书
2501_915909061 天前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者81 天前
TraceEagle 代理抓包详解,无感代理、去证书绑定与 HTTP/3 解密能力解析
网络协议·计算机网络·网络安全·ios·adb·https·udp