Skip to content

iOS 14.0 YYAnimatedImageView 无法显示正常图片 #149

Closed
@f0117570

Description

@f0117570

版本1.0.4

iOS 14.0 YYAnimatedImageView 无法显示正常图片

14.0 系统调用了此方法,YYAnimatedImageView没有正确处理

  • (void)displayLayer:(CALayer *)layer;

Activity

MyHZ

MyHZ commented on Jul 8, 2020

@MyHZ

YYAnimatedImageView.m

  • (void)displayLayer:(CALayer *)layer {
    UIImage *currentFrame = _curFrame;
    if (!currentFrame) {
    currentFrame = self.image;
    }
    if (currentFrame) {
    layer.contentsScale = currentFrame.scale;
    layer.contents = (__bridge id)currentFrame.CGImage;
    }
    }
mars2639

mars2639 commented on Jul 31, 2020

@mars2639

YYAnimatedImageView.m

- (void)displayLayer:(CALayer *)layer {
    if (_curFrame) {
        layer.contents = (__bridge id)_curFrame.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];
        }
    }
}
cityleaf

cityleaf commented on Sep 18, 2020

@cityleaf

我们没有改ibireme的源码,因为日后他可能会要升级,我是用类别hook了那个方法:displayLayer:

+ (void)load
{
    Method a = class_getInstanceMethod(self, @selector(displayLayer:));
    Method b = class_getInstanceMethod(self, @selector(swizzing_displayLayer:));
    method_exchangeImplementations(a, b);
}

- (void)swizzing_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];
        }
    }
}
QiuYeHong90

QiuYeHong90 commented on Sep 18, 2020

@QiuYeHong90

pod 'YYImage', :git => 'https://github.com/QiuYeHong90/YYImage.git'
临时解决

CodeSlaveZhang

CodeSlaveZhang commented on Sep 19, 2020

@CodeSlaveZhang
  • (void)displayLayer:(CALayer *)layer {
    [super displayLayer:layer];
    if (_curFrame) {
    layer.contents = (__bridge id)_curFrame.CGImage;
    }
    }
paulAndKey

paulAndKey commented on Sep 25, 2020

@paulAndKey

哦豁,已解决

aixl

aixl commented on Oct 27, 2020

@aixl

pod 'YYImage', :git => 'https://github.com/QiuYeHong90/YYImage.git'
临时解决

貌似还有偶现的不显示问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @mars2639@CodeSlaveZhang@f0117570@paulAndKey@aixl

        Issue actions

          iOS 14.0 YYAnimatedImageView 无法显示正常图片 · Issue #149 · ibireme/YYImage