Sui*_*eep 1 react-native react-animated expo
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'
}
});
Run Code Online (Sandbox Code Playgroud)
上图所附代码Animated.ValueXY(100,100)改成后运行没有问题Animated.ValueXY(0,0)
任何人都可以照顾解释为什么这样的行为存在如我的想法是有这个球开始从移动,而不是x:0,y:0我想它开始移动x:100,y:100,而不是
小智 5
this.position = new Animated.ValueXY({ x: 100, y: 100 });
Run Code Online (Sandbox Code Playgroud)
尝试这个
| 归档时间: |
|
| 查看次数: |
861 次 |
| 最近记录: |