gpt4 book ai didi

react-native - 如何将抖动动画添加到 View (react-native)?

转载 作者:行者123 更新时间:2023-12-04 04:49:36 25 4
gpt4 key购买 nike

当我的密码错误时,我想摇晃下面的View
例如:

它应该是从位置 10 到位置 20 的 translateX 4 次 1 秒。
然后应该停在原地 10。

放置 10(我的意思是 View 的 X 位置)

startShake = () => {
Animated.loop(
Animated.sequence([
Animated.timing(this.animatedValue, {toValue: 1, duration: 150, easing: Easing.linear, useNativeDriver: true}),
Animated.timing(this.animatedValue, {toValue: -1, duration: 300, easing: Easing.linear, useNativeDriver: true}),
Animated.timing(this.animatedValue, {toValue: 0, duration: 150, easing: Easing.linear, useNativeDriver: true}),
])
).start();
}

<Animated.View style={{transform: [{
translateX: this.animatedValue.interpolate({
inputRange: [0, 0],
outputRange: [0, 0]
})
}]
}}>

</Animated.View>

最佳答案

谢谢大家的回答。

我刚刚解决了使用以下代码编辑我的代码

  constructor(props) {
super(props)
this.shakeAnimation = new Animated.Value(0);
}

startShake = () => {
Animated.sequence([
Animated.timing(this.shakeAnimation, { toValue: 10, duration: 100, useNativeDriver: true }),
Animated.timing(this.shakeAnimation, { toValue: -10, duration: 100, useNativeDriver: true }),
Animated.timing(this.shakeAnimation, { toValue: 10, duration: 100, useNativeDriver: true }),
Animated.timing(this.shakeAnimation, { toValue: 0, duration: 100, useNativeDriver: true })
]).start();
}

<Animated.View style={{ transform: [{translateX: this.shakeAnimation}] }}>

</Animated.View>

关于react-native - 如何将抖动动画添加到 View (react-native)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57686598/

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