Cri*_* Tr 4 reactjs react-native
我已经使用做了一些简单的动画,Animated从反应本土
第一onPress后如预期的动画作品,但我无法弄清楚如何重置,以使其成为下一个水龙头工作。
constructor(props) {
super(props);
this.spinValue = new Animated.Value(0);
// Second interpolate beginning and end values (in this case 0 and 1)
this.spin = this.spinValue.interpolate({
inputRange: [0, 1, 2, 3, 4],
outputRange: ['0deg', '4deg', '0deg', '-4deg', '0deg']
});
}
handlePress() {
// First set up animation
Animated.timing(
this.spinValue,
{
toValue: 4,
duration: 300,
}
).start();
}
Run Code Online (Sandbox Code Playgroud)
并在渲染
<TouchableWithoutFeedback onPress={() => { this.handlePress(); }} >
<Animated.Image
source={someImg}
style={{ height: undefined, width: undefined, flex: 1, transform: [{ rotate: this.spin }, { perspective: 1000 }] }}
resizeMode={'contain'}
resizeMethod="resize"
/>
</TouchableWithoutFeedback>
Run Code Online (Sandbox Code Playgroud)
有什么建议么?谢谢
Ant*_*amp 24
您可以this.spinValue.setValue(0)用来重置它。您可以将其添加到的开头handlePress。
| 归档时间: |
|
| 查看次数: |
3585 次 |
| 最近记录: |