升级xcode12后,编译运行App发现大片大片的图片加载不出来,包括weex的图片和YYAnimateView的图片都有问题。
经过一番研究之后,发现是iOS 14下UIKit对 `displayLayer:`的处理机制有所变化。
`displayLayer:`是`CALayerDelegate`的代理方法。在iOS 14之前,UIKit在调用这个方法之前就会去渲染`UIImageView.image`。
而在iOS 14,UIKit则是先去调用代理方法,如果你实现了`displayLayer:`这个方法,那么UIKit就不会再去渲染了。
如果改成下面这样就可以正常加载了:
```
- (void)displayLayer:(CALayer *)layer {
UIImage *currentFrame = _curFrame;
if (currentFrame) {
layer.contentsScale = currentFrame.scale;
layer.contents = (__bridge id)currentFrame.CGImage;
} else {
// If we have no animation frames, call super implementation. iOS 14+ UIImageView use this delegate method for rendering.
if ([UIImageView instancesRespondToSelector:@selector(displayLayer:)]) {
[super displayLayer:layer];
}
}
// if (_curFrame) {
// layer.contents = (__bridge id)_curFrame.CGImage;
// }
}
```
参考:
1. https://github.com/apache/incubator-weex/issues/3265
2. https://github.com/ibireme/YYWebImage/issues/242
3. https://github.com/SDWebImage/SDWebImage/issues/3040
原地址:https://y500.me/2020/09/29/image-not-render-on-ios14/
来源:oschina
链接:https://my.oschina.net/u/4382386/blog/4658144