import React, { Component } from 'react';
import { View, StyleSheet, Animated } from 'react-native';
export default class Ball extends Component {
componentWillMount(){
this.position = new Animated.ValueXY(0,0);
Animated.spring(this.position, {
toValue: {x :200, y: 500}
}).start();
}
render() {
return (
<Animated.View style={this.position.getLayout()}>
<View style={styles.ball} />
</Animated.View>
);
}
}
const styles = StyleSheet.create({
ball: {
height: 60,
width: 60,
borderRadius: 30,
borderWidth: 30,
borderColor: 'green'
}
});
Animated.ValueXY(100,100)
上图所附的代码改成后运行没有问题Animated.ValueXY(0,0)
任何人都可以解释为什么存在这种行为,因为我的想法不是让这个球开始移动,x:0,y:0
我希望它开始x:100,y:100
移动