我想要 2 个视图,它们同时像一个没有旋转的圆圈一样变换。第一个视图从顶部开始,第二个视图从底部开始。我已经问过如何用一种观点来做到这一点。我不让它运行有两个视图。 之前的问题
//import liraries
import React, { Component } from 'react';
import { View, Text, StyleSheet, Animated, Button, TouchableOpacity } from 'react-native';
// create a component
export default class App extends Component {
constructor() {
super()
this.animated = new Animated.Value(0);
this.animated2 = new Animated.Value(0);
var range = 1, snapshot = 50, radius = 100;
/// translateX
var inputRange = []
var outputRange = []
var outputRange2 = []
for (var i=0; i<=snapshot; ++i) {
var value = i/snapshot;
var move = Math.sin(value * Math.PI * 2) * radius;
inputRange.push(value);
outputRange.push(move);
outputRange2.push(-move);
}
translateX = this.animated.interpolate({ inputRange, outputRange });
translateX2 = this.animated2.interpolate({inputRange, outputRange2})
/// translateY
var inputRange = []
var outputRange = []
var outputRange2 = []
for (var i=0; i<=snapshot; ++i) {
var value = i/snapshot;
var move = -Math.cos(value * Math.PI * 2) * radius;
inputRange.push(value);
outputRange.push(move);
outputRange2.push(-move);
}
translateY = this.animated.interpolate({ inputRange, outputRange });
translateY2 = this.animated2.interpolate({inputRange, outputRange2})
}
animate() {
this.animated.setValue(0)
Animated.timing(this.animated, {
toValue: 1,
duration: 10000,
}).start();
this.animated2.setValue(0)
Animated.timing(this.animated2, {
toValue: 1,
duration: 10000,
}).start();
}
render() {
//const transform = [{ translateY: this.translateY }, {translateX: this.translateX}];
return (
<View style={styles.container}>
<Animated.View style={
[{ transform: [{ translateY: translateY }, {translateX: translateX}] }]}>
<TouchableOpacity style={styles.btn}>
<Text>hallo</Text>
</TouchableOpacity>
</Animated.View>
<Animated.View style={
[{ transform: [{ translateY: translateY2 }, {translateX: translateX2}] }]}>
<TouchableOpacity style={styles.btn}>
<Text>hallo</Text>
</TouchableOpacity>
</Animated.View>
<Button title="Test" onPress={() => {
this.animate()
}} />
</View>
);
}
}
// define your styles
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2c3e50',
},
btn2: {
justifyContent: 'center',
alignItems: 'flex-end',
alignSelf: 'flex-end'
},
btn: {
backgroundColor: 'red',
justifyContent: 'center',
alignItems: 'center',
width: 50,
}
});