期望效果:
我想要创建一个与手指拖动速度同步的平滑滑动View (左或右)的基本动画。
目前,我在处理所有手势的父组件中使用Animated.spring。然后,我在子组件中使用transform,translateX向左或向右滑动View。
例如:
Root.js(处理手势的父组件)
_handlePanResponderMove(e: Object, gestureState: Object) {
let dx = gestureState.moveX - this.state.swipeStart;
Animated.spring(
this.state.slideValue,
{
toValue: newValue,
velocity: gestureState.vx,
tension: 2,
friction: 8,
}).start();
}Navigation.js(幻灯片子组件)
render(){
<Animated.View style={[styles.navigation,{transform: [{translateX: this.props.slideValue}]}]}>
<View >
</View>
</Animated.View>
}问题:
有粘性/滞后的行为与动画,而不是一个平稳的移动,以步调手指滑动的感觉。
到目前为止我的推理:
根据我有限的动画经验-- Animated.spring, Animated.ease和Animated.timing并没有很好地描述我所追求的同样节奏的滑动运动--但我想我需要使用其中的一种来优化本地性能(否则,我只会使用.setState(slideValue),用手指的当前位置来计算出View的位置)。
问题:
使用优化的React本地动画库来描述这种平滑滑动动画的首选方法是什么?
我已经尝试过的:
1)使用Animated.timing,并将duration low和easing设置为线性(我对应该做什么最好的猜测)
Animated.timing(
this.state.navSlideValue,
{
toValue: newValue,
duration: 10,
easing: Easing.linear
}).start();2)向上移动tension on Animated.spring
Animated.spring(
this.state.navSlideValue,
{
toValue: newValue,
velocity: (gestureState.vx),
tension: 300,
friction: 30,
}).start(); 发布于 2016-11-06 11:25:51
预设函数timing,spring对于在给定的条件下将动画运行到指定的值非常有用。如果要将Animated值绑定到事件,则可以使用Animated.event:
PanResponder.create({
// on each move event, set slideValue to gestureState.dx -- the
// first value `null` ignores the first `event` argument
onPanResponderMove: Animated.event([
null, {dx: this.state.slideValue}
])
// ...rest of your panResponder handlers
});https://stackoverflow.com/questions/40439975
复制相似问题