【发布时间】:2018-04-26 16:27:11
【问题描述】:
Animated API 有 2 个问题。
第一个:我可以使用以下代码从左到右显示图像。我想将图像从位置X=40 (leftPadding), Y=100(topPadding), height:20, width:20 缩放到X=20, Y=10, height:250, width:300。我如何做到这一点?
我的代码:
import React, { Component } from 'react';
import { StyleSheet, Text, Image, Animated, Easing, View, Button } from 'react-native';
class MyTestComp extends Component {
componentWillMount() {
this.animatedValue = new Animated.Value(0);
}
buttonPress(){
this.animatedValue.setValue(0);
Animated.timing(this.animatedValue,{
toValue:1,
duration:1000,
Easing: Easing
}).start()
}
render() {
const translateX = this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [-500, 1]
})
const transform = [{translateX}];
return (
<View>
<Text>MyTestComp</Text>
<Animated.View style={transform}>
<Image
source={require('./assets/17.jpg')}
style={{width:300, height:250}}
/>
</Animated.View>
<View style={{marginTop:10}}>
<Button title="Click Me" onPress={()=> this.buttonPress()} />
</View>
</View>
);
}
}
export default MyTestComp;
第二次:每次运行动画时,我都会遇到异常:
我找不到任何关于此的文档。如何使用transform 属性。
非常感谢。
【问题讨论】:
-
如果您的代码与您在此处发布的代码相同,那么我认为您的问题只是语法错误。
style={transform}应该是style={{ transform }}。
标签: reactjs react-native react-animated react-animations