iOS 14 YYAnimatedImageView加載圖片失敗處理


1.問題出在YYAnimatedImageView源碼一個方法中

- (void)displayLayer:(CALayer *)layer {

    if (_curFrame) {

        layer.contents = (__bridge id)_curFrame.CGImage;

    }

}

2.解決辦法

第一種方法:修改源碼方法

- (void)displayLayer:(CALayer *)layer {

    if (_curFrame) {

        layer.contents = (__bridge id)_curFrame.CGImage;

    }else{

        if (@available(iOS 14.0, *)) {

            [super displayLayer:layer];

        }

    }

}

第二種方法:運行時

#import "YYAnimatedImageView+iOS14.h"

#import <objc/runtime.h>

 

@implementation YYAnimatedImageView (iOS14)

+ (void)load {

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        Method method1;

        Method method2;

        method1 = class_getInstanceMethod([self class], @selector(lz_displayLayer:));

        method2 = class_getInstanceMethod([self class], @selector(displayLayer:));

        method_exchangeImplementations(method1, method2);

    });

}

- (void)lz_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];

        }

    }

}

 

@end


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM