YYAnimatedImageView+iOS14.m 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // YYAnimatedImageView+iOS14.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2025/7/2.
  6. //
  7. #import "YYAnimatedImageView+iOS14.h"
  8. #import <objc/runtime.h>
  9. @implementation YYAnimatedImageView (iOS14)
  10. + (void)load {
  11. static dispatch_once_t onceToken;
  12. dispatch_once(&onceToken, ^{
  13. Method method1;
  14. Method method2;
  15. method1 = class_getInstanceMethod([self class], @selector(lz_displayLayer:));
  16. method2 = class_getInstanceMethod([self class], @selector(displayLayer:));
  17. method_exchangeImplementations(method1, method2);
  18. });
  19. }
  20. - (void)lz_displayLayer:(CALayer *)layer {
  21. Ivar ivar = class_getInstanceVariable(self.class, "_curFrame");
  22. UIImage *_curFrame = object_getIvar(self, ivar);
  23. if (_curFrame) {
  24. layer.contents = (__bridge id)_curFrame.CGImage;
  25. }else{
  26. if (@available(iOS 14.0, *)) {
  27. [super displayLayer:layer];
  28. }
  29. }
  30. }
  31. @end