我想要一個動畫在我打開我的鍵盤時執行,並在關閉它時恢復。鍵盤監聽器不能改變這個狀態
的問題是:
不確定是不是(評估 'this.state.scaleValue')
對象我有Keyboard.listener其工作良好。
國家:
this.state = {
scaleValue: new Animated.Value(0),
}
動畫查看
<Animated.View style={styles.logoContainer,
{
transform: [
{scale: logoScale}
]
}
}>
<Image source={require('./someimage.png')} style={{width: 64, height: 64}} />
</Animated.View>
插值
const logoScale = this.state.scaleValue.interpolate({
inputRange: [0, 0.5, 1],
outputRange: [1, 0.5, 0]
});
觸發
_keyboardDidShow() {
this.state.scaleValue.setValue(0);
Animated.timing(
this.state.ScaleValue,
{
toValue: 1,
duration: 300,
easing: Easing.easeOutBack
}
).start();
}
所以,當我將觸發器的代碼放入一個函數中,並將其命名爲onPress with Touchable時,它就可以工作。
'this'是不提供給'Animated.timing'函數內部的相同上下文。你需要綁定:'this._keyboardDidShow = this._keyboardDidShow.bind(this)'如果這不起作用,你甚至可以在'timing'的調用之上設置'let me = this'(並將其稱爲'我'在方法內)。 – G0dsquad
@ G0dsquad你說得對。謝謝。 – Mirakurun
沒問題,因此我添加了它作爲你的答案:) – G0dsquad