美文网首页
YYAnimatedImageView

YYAnimatedImageView

作者: iVikings | 来源:发表于2021-12-15 15:39 被阅读0次

    import <YYKit/YYAnimatedImageView.h>

    import <objc/runtime.h>

    @interface YYAnimatedImageView (Layer)
    
    @end
    
    @implementation YYAnimatedImageView (Layer)
    
    + (void)load {
        Method displayLayerMethod    = class_getInstanceMethod(self, @selector(displayLayer:));
        Method displayLayerNewMethod = class_getInstanceMethod(self, @selector(displayLayerNew:));
        method_exchangeImplementations(displayLayerMethod, displayLayerNewMethod);
    }
    
    - (void)displayLayerNew:(CALayer *)layer {
        Ivar imgIvar = class_getInstanceVariable([self class], "_curFrame");
        UIImage *img = object_getIvar(self, imgIvar);
        if (img) {
            layer.contents = (__bridge id)img.CGImage;
        } else {
            if (@available(iOS 14.0, *)) {
                [super displayLayer:layer];
            }
        }
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:YYAnimatedImageView

          本文链接:https://www.haomeiwen.com/subject/qilpfrtx.html