加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native动画的坑

发布时间:2020-12-15 06:57:43 所属栏目:百科 来源:网络整理
导读:准备做一个循环上下滚动的react-native动画,但是遇到了坑.我在调试的过程中把Animated.Image改成了Image,然后忘了改过来: spinAniamte = ()= { if (this.animateToValue = carmaHeight){ this.animateToValue = 0; } else { this.animateToValue = carmaHei

准备做一个循环上下滚动的react-native动画,但是遇到了坑.我在调试的过程中把Animated.Image改成了Image,然后忘了改过来:
spinAniamte = ()=> {
if (this.animateToValue >= carmaHeight){
this.animateToValue = 0;
} else {
this.animateToValue = carmaHeight;
}
Animated.timing( // 随时间变化而执行的动画类型
this.spinValueOne,// 动画中的变量值
{
toValue: this.animateToValue,// 透明度最终变为1,即完全不透明
duration:2000,
}
).start((finished)=>{
return this.spinAniamte();
});
}

componentDidMount() {
  this.spinAniamte();
}

  render(){
      return (
        <View style={{flex:1,justifyContent:'center'}}>
            <Image  capInsets={{top:20,right:20,left:20,bottom:20}} source={{uri:'scan_border'}} style={{alignItems:'center',position:"absolute",left:carmaLeft,right:carmaLeft,height:carmaHeight}} resizeMode={'stretch'}>
                <Image source={{uri:'scanLine'}} style={{position:"absolute",top:this.spinValueOne,height:7,width:200}}></Animated.Image>
            </Image>
        </View>
    );
}

结果到Animated.timing方法里面去访问 this.spinValueOne会一直报错:
Attempted to assign to readonly property.截图:

如果Animated.timing,没有对应的Animated组件就会报这种错!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读