React Native:如何用translateX动画视图的位置?

问题描述:

我尝试了“ENTER现在”按钮被按下时,将我的观点关闭屏幕:React Native:如何用translateX动画视图的位置?

enter image description here

export class Onboarding extends Component { 

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

    hideOnboarding() { 
    console.log("hiding"); // <-------- prints out when button pressed 
    Animated.timing(
     this.state.offsetX, 
     { toValue: new Animated.Value(-100) } 
    ).start(); 
    } 

    render() { 
    return (
     <Animated.View style={{ transform: [{translateX: this.state.offsetX}] }}> 
     ... 
     <TouchableOpacity onPress={() => { this.hideOnboarding() } }> 
      <View style={styles.enterButton}> 
      <Text style={styles.buttonText}>Enter Now</Text> 
      </View> 
     </TouchableOpacity> 
     </Animated.View> 
    ); 

但是,当我点击我的按钮没有被感动。我的控制台声明虽然工作。有谁知道我做错了什么?

我认为你需要改变:

{ toValue: new Animated.Value(-100) } 

{ toValue: -100 } 
+0

对我来说说不确定是不是(评估 'value.getValue')@马特船尾的物体 – Vijay