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
移动
答案 0 :(得分:1)
this.position = new Animated.ValueXY({ x: 100, y: 100 });
试试这个