美文网首页
react native 动画使用

react native 动画使用

作者: IDO0 | 来源:发表于2017-07-06 17:28 被阅读0次

·一:动画组件:
Animated.Image
Animated.Text
Animated.View

二:动画函数:
1:Animated.timing() -- 推动一个值按照一个过渡曲线而随时间变化。Easing
模块定义了很多缓冲曲线函数。
2:Animated.decay() -- 推动一个值以一个初始的速度和一个衰减系数逐渐变为0。
3:Animated.spring() -- 产生一个基于 ReboundOrigami 实现的Spring动画。它会在 toValue
值更新的同时跟踪当前的速度状态,以确保动画连贯。

三:使用步骤
1:初始化动画属性值 Animated.value() Animated.valueXY()
2:将动画属性值关联到动画组件的属性上
3:选择执行动画的函数 timing decay spring

第一种普通动画:
效果图:


animated.gif

code:
componentDidMount() {
this.startAnimated();
}

startAnimated = () => {
this.state.bounceValue.setValue(2);//每次循环的起始值
Animated.timing(this.state.bounceValue, {
toValue: 5,
duration: 4000,
easing: Easing.back(),
}).start(() => this.startAnimated());//循环执行
}

render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Animated.View
style={{
width: 50,
height: 50,
backgroundColor: 'red',
transform: [{ scale: this.state.bounceValue }]
}}
/>
</View>
);
}
第二种手势动画:
效果图:


animat.gif pho.png

给动画添加手势并监听

tran.png

将动画属性关联到动画组件上

listenlog.png

监听打印的log

一个好用的动画库:https://github.com/oblador/react-native-animatable

相关文章

网友评论

      本文标题:react native 动画使用

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