升級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/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/147142.html
標籤:python
上一篇:如何打造短期爆發式增長的爆款文章
