如何在响应本机IOS中运行GIF?

时间:2018-07-17 11:18:52

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

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

1 个答案:

答案 0 :(得分:0)

如果您控制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