【发布时间】:2019-05-25 01:34:10
【问题描述】:
我正在尝试为某些组件设置动画。我只想更改视图宽度的大小。我一直在寻找制作简单动画的最简单方法。我正在使用“Animated”库。我无法完成这项工作
我正在寻找一些教程,但它不起作用。由于某种原因,代码没有重新调整“Animated.View”的初始宽度,它是在构造函数上声明的变量,就像这个“animationwidth = new Animated.Value(11);"。不知道问题出在变量的声明、“Animated.View”的样式还是“animated.timing”函数中
import React, { Component } from 'react';
import {Animated,Text,Alert,View, Image, Button} from 'react-native';
export default class Game extends Component {
constructor(props) {
super(props);
this.state = {
opa: 1
};
animationwidth = new Animated.Value(11);
}
componentDidmount(){
Animated.timing(this.animationwidth, {
toValue: 300
}).start()
}
render(){
return(
<View style={{flex:1,alignItems:'center',backgroundColor:'green',justifyContent:'center'}}>
<Animated.View style={{ height:250, width:this.animationwidth ,backgroundColor:'blue'}}/>
</View>
)
}
}
【问题讨论】: