首页 > 解决方案 > react-native: onPanMove 期间 Animated.View 的动画位置

问题描述

我已经设置了一个动画并想要为视图设置动画,因此当用户触摸移动视图时,视图会在 y 轴上跟随。

我尝试使用 Animated.event 进行设置,但它不起作用。有人可以解释一下 Animated.event 在 panResponder 中是如何工作的吗?

这就是我所拥有的:

const onPanMove = (evt: GestureResponderEvent, state: PanResponderGestureState) => {
    Animated.event([null, {dy: new Animated.Value(state.dy)}], {useNativeDriver: true});
};

但什么也没有发生。我也搜索了很多,但没有找到任何好的文档。

当我用它替换event它时,timing它可以工作,但它非常滞后,因为它总是等待 touchmove 暂停。

Animated.timing(
    this.state.position,
    {
        toValue: startY - state.dy,
        duration: 0,
        //easing: this.props.easing,
        useNativeDriver: true
    }
).start();

标签: react-native

解决方案


推荐阅读