【发布时间】:2017-11-25 20:19:03
【问题描述】:
我正在尝试在本机反应中创建一个旋转的地球动画。我的方法是有两个组件,第一个是一个圆形容器,它将充当地球。第二个将是地球的孩子,将是地球的背景图像,将在视图中滚动。
我能够让背景图像在全球范围内滚动,它看起来很不错。
我希望背景图像与地球容器具有相同的高度,但我希望它更宽,以便它在地球上不断滚动,创建一个旋转的地球动画。我目前遇到宽度被切断的问题,因此当图像滚动时,它只是滚动的初始视图,而图像的其余部分已经丢失。
我尝试了各种方法,例如使用图像 resizeModes、硬编码高度和宽度值以及将高度和宽度设置为未定义。
这是我最成功的尝试的渲染:
render() {
const { animatedRotate } = this.state;
const scroll = animatedRotate.interpolate({
inputRange: [0, 1],
outputRange: [1, 200]
});
return (
<View style={styles.globeContainer}>
<Animated.Image
source={ require('../resources/world.png') }
//resizeMode="cover"
//resizeMode="center"
//resiveMode=""
style={[styles.globe, {transform: [{translateX: scroll}]}]}
/>
</View>
);
}
const styles = StyleSheet.create({
globeContainer: {
height: 150,
width: 150,
borderRadius: 75,
backgroundColor: '#f0f0f5',
overflow: 'visible', //visible for testing only
borderWidth: 0.5,
borderColor: '#D3D3D3',
borderRightColor: '#D3D3D3',
borderRightWidth: 10,
alignSelf: 'center',
},
globe: {
height: 150,
width: undefined
}
});
这里是输出的截图:
有人对此有想法吗?
【问题讨论】:
标签: image react-native react-native-image