【问题标题】:Animated.loop image动画循环图像
【发布时间】:2017-06-23 08:00:01
【问题描述】:

早在 1996 年,我就为客户创建了旋转徽标,因为我可以,现在在 2017 年我又回来了,感谢Animated

<hr /> 下方的代码可以运行,但重新启动时会出现小问题。

知道如何使用Animated.loop 吗?它不会:«每次到达终点,它都会重置并从头开始»。

Animated.loop(
  Animated.timing(this.state.spinValue, {
    toValue: 1,
    duration: this.props.duration,
    easing: Easing.linear,
    useNativeDriver: true
  })
).start();

static defaultProps = {
  duration: 60 / (33 + 1/3) * 1000
}

constructor (props) {
  super(props);
  this.state = {
    spinValue: new Animated.Value(0)
  };
}

componentDidMount () {
  this._animate();
}

_animate () {
  Animated.timing(this.state.spinValue, {
    toValue: 1,
    duration: this.props.duration,
    easing: Easing.linear,
    useNativeDriver: true
  }).start(event => {
    if (event.finished) {
      this.setState({
        spinValue: new Animated.Value(0)
      }, this._animate.bind(this));
    }
  });
}

render () {
  const spin = this.state.spinValue.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '360deg']
  });
  return (
    <View style={ Loading.style.container }>
      <Animated.Image
        source={ logo }
        style={{ transform: [{ rotate: spin }] }}
      />
    </View>
  );
}

【问题讨论】:

    标签: react-native react-animated


    【解决方案1】:

    易于使用 react-native-LoopAnimation.js' https://github.com/Infinity0106/react-native-LoopAnimation

    import LoopAnimation from 'react-native-LoopAnimation.js' 
    ...
    render() {
      //you can also use, like source={imgSource}
      const imgSource=
      {uri:'http://www.menucool.com/slider/jsImgSlider/images/image-slider-2.jpg',width:700,height:306};
    
      return (
        <View style={{flex:1}}>
          {/*this is the background animation */}
          <LoopAnimation source={require('./img/back.jpg')} duration={10000} />
            <View style={{
              flex: 1,
              flexDirection: 'column',
              justifyContent: 'center',
              alignItems: 'center',
            }}>
            {/*Content goes here*/}
            <View style={{width: 200, height: 400, backgroundColor: 'powderblue'}} />
            </View>
        </View>
       );
      }
    

    【讨论】:

    • 图书馆似乎在使用Animated.sequence。我想坚持纯 React Native。
    • 上述库没有提供许可信息,因此不能在实际应用中使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2023-04-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多