React native 如何在Reac Native中设置动画的初始偏移量
我有一个图像,我想在循环中将它从React native 如何在Reac Native中设置动画的初始偏移量,react-native,React Native,我有一个图像,我想在循环中将它从imageWidth水平转换为-imageWidth,但我想让它在第一个循环中从0开始。我尝试在设置定时后立即设置值(0),但它仍然从imageWidth开始。我现在拥有的代码是: this.translateValue = new Animated.Value(0) translate() { this.translateValue.setValue(this.backgroundImageWidth) Animated.timing(
imageWidth
水平转换为-imageWidth
,但我想让它在第一个循环中从0
开始。我尝试在设置定时后立即设置值(0),但它仍然从imageWidth
开始。我现在拥有的代码是:
this.translateValue = new Animated.Value(0)
translate() {
this.translateValue.setValue(this.backgroundImageWidth)
Animated.timing(
this.translateValue,
{
toValue: -this.backgroundImageWidth,
duration: 20000,
easing: Easing.linear
}
).start(()=>this.translate())
}
componentDidMount() {
this.translate()
this.translateValue.setValue(0)
...
}
render() {
return(
<Animated.Image
style={{
flex: 1,
position: 'absolute',
left: this.translateValue,
}}
resizeMode={Image.resizeMode.cover}
source={this.backgroundImage}
/>
)
this.translateValue=新的动画.Value(0)
翻译(){
this.translateValue.setValue(this.backgroundImageWidth)
时间(
这是翻译价值,
{
toValue:-this.backgroundImageWidth,
持续时间:20000,
放松:放松。线性
}
).start(()=>this.translate())
}
componentDidMount(){
这个
此.translateValue.setValue(0)
...
}
render(){
返回(
)
didmount方法中调用translate
之前,是否应调用this.translateValue.setValue(0)
?didmount方法中调用translate
之前,是否应调用this.translateValue.setValue(0)
?