简体   繁体   English

如何在单轴上(例如,对于特定旋转)在水平或垂直轴上制作图像动画

[英]How can I make animation of image in a single axis ie., for a particular rotation - on horizontal or vertical axis

I am trying to spin an Image it is basically to show that a coin is flipped ( coin Tossing animation ) I have applied this basic animation to the image but it is not getting animated, 我正在尝试旋转图像,基本上是为了显示硬币被翻转了(投币动画)。我已将基本动画应用于图像,但没有获得动画效果,

The image is stationary while I tested it on emulator 我在模拟器上测试图像时图像是静止的

this is my index.android.js file : 这是我的index.android.js文件:

 import React, { Component } from 'react'; import { AppRegistry, View, Animated, Easing } from 'react-native'; export default class animateTest extends Component { constructor(props) { super(props); this.spinValue = new Animated.Value(0); } componentDidMount() { this.spin(); } spin() { this.spinValue.setValue(0); Animated.timing( this.spinValue, { toValue: 1, duration: 1500, easing: Easing.linear, } ).start(); } render() { const spin = this.spinValue.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '1440deg'], useNativeDriver: true }); return ( <View style={styles.ViewStyle}> <Animated.Image style={[ styles.coinStyle, { width: 150, height: 150, transform: [ { rotate: spin }, ] }, ]} source={require('./Images/Coin_Tail.png')} /> </View> ); } } const styles = { ViewStyle: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'black', } }; AppRegistry.registerComponent('animateTest', () => animateTest); 

I got it how to do this 我知道如何做到这一点

-it's only a small change I just added rotateX in my animation -这只是我在动画中添加了rotateX的一个小更改

here's the code: 这是代码:

 import React, { Component } from 'react'; import { AppRegistry, View, Animated, Easing } from 'react-native'; export default class animateTest extends Component { constructor(props) { super(props); this.spinValue = new Animated.Value(0); } componentDidMount() { this.spin(); } spin() { this.spinValue.setValue(0); Animated.timing( this.spinValue, { toValue: 1, duration: 1500, easing: Easing.linear, } ).start(); } render() { const spin = this.spinValue.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '1440deg'], useNativeDriver: true }); return ( <View style={styles.ViewStyle}> <Animated.Image style={[ styles.coinStyle, { width: 150, height: 150, transform: [ { rotateY: spin }, ] }, ]} source={require('./Images/Coin_Tail.png')} /> </View> ); } } const styles = { ViewStyle: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'black', } }; AppRegistry.registerComponent('animateTest', () => animateTest); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM