美文网首页
RN动画实现

RN动画实现

作者: 赵鸿伟1997 | 来源:发表于2018-11-02 10:54 被阅读0次

一、动画使用

constructor(props) {

    super(props);

    this.state = {

      // 1. 初始化动画值

      opacity: new Animated.Value(0)

    };

}

render() {

    return (

      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>

        <Animated.Text

          style={{

            // 2. 将动画值绑定到style的属性:opacity透明度

            opacity: this.state.fadeAnim,

          }}

        >

          RN的动画使用

        </Animated.Text>

        <Button title="开启动画" onPress={this.press} />

      </View>

    );

}

press = () => {

    //3.动画处理以及开启

    Animated.timing(this.state.scale, {

      toValue: 3,

      duration: 5000

    }).start();

};

press = () => {

    //3.动画处理以及开启

    const animations = [

      Animated.timing(this.state.opacity, {

        toValue: 3,

        duration: 5000

      }),

      Animated.timing(this.state.width, {

        toValue: 500

      }),

      Animated.timing(this.state.height, {

        toValue: 500

      })

    ];

    Animated.stagger(5000, animations).start();

};

相关文章

网友评论

      本文标题:RN动画实现

      本文链接:https://www.haomeiwen.com/subject/aipqxqtx.html