我一直在尝试获得一个简单的动画,以与PanResponder和React Animated API一起使用。这是我到目前为止所拥有的:
export default class Main extends Component {
constructor(props) {
super(props)
this.state = {
y: new Animated.Value(0)
}
this._panResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onPanResponderMove: Animated.event([
null,
{
dy: this.state.y
}
]),
});
}
render() {
let { y } = this.state;
return (
<View {...this._panResponder.panHandlers} style={{ flex: 1 }} >
<LinearGradient start={{ x: 1.0, y: 0 }} end={{ x: 0.0, y: 1.0 }} colors={['rgba(0,187,9,0.575)', 'rgba(255, 217, 0 , 0.719)']} style={{ alignItems: "center", justifyContent: "center", margin: 0, flex: 1, padding: 20, width: "100%" }}>
<ResponsiveImage style={{ transform: [{ rotateZ: y + " deg" }, { perspective: 1000 }], marginBottom: 100 }} source={require('./assets/images/logo.png')} initWidth="225" initHeight="220" />
</LinearGradient>
</View>
);
}
}
使用上面附加的代码,旋转动画无效。仅当我使用以下代码代替当前的onPanResponderMove方法时,该方法才有效。
onPanResponderMove: (a,b)=>{this.setState({y: b.dy}) }
为什么Animated.Event方法不起作用?