关于ios:iOS-14下面图片无法加载包括weexYYAnimateViewSDAnimatedImageView

3次阅读

共计 852 个字符,预计需要花费 3 分钟才能阅读完成。

降级 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/inc…
  2. https://github.com/ibireme/YY…
  3. https://github.com/SDWebImage…

原地址:https://y500.me/2020/09/29/im…

正文完
 0