2017-07-28 47 views
0

我試圖動畫視圖時按下按鈕向右滑動,我現在有下面的代碼,但不斷收到陣營本土動畫不確定是不是一個對象錯誤

不確定是不是一個對象(評估此。 state.panelPos)錯誤。我不明白代碼有什麼問題。有什麼建議麼?

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


slideOutPanel(){ 
Animated.timing(this.state.panelPos,{ 
      toValue: 300, 
      duration: 1000, 
     }).start(); 
}; 

render(){return(
<View style = {styles.container}> 

    <View style = {styles.lContainer}> 

     <View style = {styles.playerLife}> 

      <View style = {styles.lifeButtonRow}> 
       <LifeButton/> 
       <LifeButton/> 
      </View> 
      <View style = {styles.lifeButtonRow}> 
       <LifeButton/> 
       <LifeButton/> 
      </View>  

      <Text>text</Text> 
     </View> 

     <Animated.View style = {[styles.panel,{transform: [{translateX: this.state.panelPos}]}]}> 
      <Image style = {styles.cmd_panel} source={require('image')}/> 
     </Animated.View> 
    </View> 
    <View style = {styles.portrait}> 
     <Button title = {'push'} onPress = {this.slideOutPanel}/> 
    </View> 
</View>); 

回答

1

否則,一切似乎是正確的,但背景下,這個沒有正確的參數設置:onPress={this.slideOutPanel}

或者:onPress={() => this.slideOutPanel()}

或:onPress={this.slideOutPanel.bind(this)}

+0

當然是謝謝 – user3074140

相關問題