Skip to content

昨天反馈你的图片不显示的问题我找到了 是iOS14以后的系统  #24

@love865122909

Description

@love865122909

原因YYAnimatedImageView不显示图片
在YYAnimatedImageView类里加入

  • (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];
    }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions