【问题标题】:Image cannot show image in iOS 14 React Native图像无法在 iOS 14 React Native 中显示图像
【发布时间】:2022-01-01 18:37:24
【问题描述】:

获取本地图像不加载的问题,只是在 Ios 中显示为空白

<Image source={ImagePath.headerBgImage} style={{ width: "100%" }} />;

【问题讨论】:

    标签: react-native image ios14


    【解决方案1】:

    如果我理解正确,_currentFrame 应该是动画图像, 所以如果是静止图像,我们可以使用 UIImage 实现 处理图像渲染

    react-native/Libraries/Image/RCTUIImageViewAnimated.m 或在 Pod 中 React- RCTImage>RCTUIImageViewAnimated.m

    1c634a9 中的第 283 到 289 行

     - (void)displayLayer:(CALayer *)layer 
     { 
       if (_currentFrame) { 
         layer.contentsScale = self.animatedImageScale; 
         layer.contents = (__bridge id)_currentFrame.CGImage; 
       } 
     } 
    

    将上面的代码替换为

    if (_currentFrame) {
        layer.contentsScale = self.animatedImageScale;
        layer.contents = (__bridge id)_currentFrame.CGImage;
      } else {
        [super displayLayer:layer];
      }
    

    【讨论】:

      【解决方案2】:

      你应该去这个文件:

      node_modules > react-native > 库 > 图片 > RCTUIImageViewAnimated.m

      然后搜索词 if (_currentFrame) 然后找到后添加 else 像这样:

       if (_currentFrame) {
          layer.contentsScale = self.animatedImageScale;
          layer.contents = (__bridge id)_currentFrame.CGImage;
        } else {
          [super displayLayer:layer];
        }
      

      有关更多信息,请参阅link

      【讨论】:

        猜你喜欢
        • 2016-11-02
        • 2016-11-03
        • 2020-05-06
        • 1970-01-01
        • 2020-02-09
        • 2015-12-17
        • 1970-01-01
        • 2021-01-05
        • 2023-01-16
        相关资源
        最近更新 更多