【问题标题】:how to run GIF once in react native IOS?如何在反应原生 IOS 中运行一次 GIF?
【发布时间】:2018-07-17 11:18:51
【问题描述】:

我使用 react native 为 android 构建了一个项目,我在项目中使用了 gif 图像,并且在 android gif 中设置了一次 gif 循环运行一次,这是真的,但是在 ios 中是循环如何强制它运行一次?

【问题讨论】:

    标签: ios iphone react-native react-native-ios


    【解决方案1】:

    如果您控制 GIF 创建,最简单的方法是将信息放入 GIF 元数据中,例如使用 gifsicle

    gifsicle my_gif.gif --no-loopcount > my_gif-noloop.gif
    

    如果不能,可以按照建议的here 编辑/node_modules/react-native/Libraries/Image/RCTGIFImageDecoder.m

    CAKeyframeAnimation *animation = [CAKeyframeAnimation 
        animationWithKeyPath:@"contents"];
        ...
        animation.repeatCount = loopCount == 0 ? 0 : loopCount; // Avoid infinite loop
        animation.fillMode = @"forwards"; // avoid image to desapear after loop
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 2016-10-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 2020-03-02
      • 1970-01-01
      • 2017-02-06
      • 2021-06-11
      相关资源
      最近更新 更多