gpt4 book ai didi

javascript - js react native : How to animate a view's position with translateX?

转载 作者:行者123 更新时间:2023-11-29 17:53:38 26 4
gpt4 key购买 nike

当按下“立即输入”按钮时,我试图将我的 View 移出屏幕:

Screenshot of app with arrows

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 }

关于javascript - js react native : How to animate a view's position with translateX?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41153311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com