想要创建一张翻转卡,但它会赢得翻转
我正在尝试创建一张简单的翻转卡,但是当我按翻转它不会,从 https://www.youtube.com/watch?v=ghlum0anok4 。
当我单击“翻盖”按钮时,什么都没有发生,甚至没有错误消息
是代码
const [isFlipped, setIsFlipped] = useState(false);
const animate = useRef(new Animated.Value(0));
const frontRef = useRef();
const backRef = useRef();
const doAFlip = () => {
Animated.timing(animate.current, {
duration: 300,
toValue: isFlipped ? 0 : 180,
useNativeDriver: true,
}).start(() => {
setIsFlipped(!isFlipped);
});
};
const interpolateFront = animate.current.interpolate({
inputRange: [0, 180],
outputRange: ['0deg', '180deg'],
});
const interpolateBack = animate.current.interpolate({
inputRange: [0, 180],
outputRange: [ '180deg', '360deg'],
});
const rotateFront = {
transform: [
{
rotateY: interpolateFront,
},
],
};
const rotateBack = {
transform: [
{
rotateY: interpolateBack,
},
],
};
和这里
<View>
<Animated.View style={[rotateFront], {backfaceVisibility: 'hidden'}}>
<View style={{backgroundColor: 'green', height: 60, width: 60}}/>
</Animated.View>
<Animated.View style={[rotateBack], {backfaceVisibility: 'hidden', position: 'absolute', top: 0}}>
<View style={{backgroundColor: 'blue', height: 60, width: 60}}/>
</Animated.View>
<Button title='Flip' onPress={doAFlip}>Flip</Button>
</View>````
I'm trying to create a Flip card, a simple one, but when I press to flip it won't, got the example from https://www.youtube.com/watch?v=ghLuM0ANOk4.
When I click the Flip button nothing happens, not even an error message
Here is the code
const [isFlipped, setIsFlipped] = useState(false);
const animate = useRef(new Animated.Value(0));
const frontRef = useRef();
const backRef = useRef();
const doAFlip = () => {
Animated.timing(animate.current, {
duration: 300,
toValue: isFlipped ? 0 : 180,
useNativeDriver: true,
}).start(() => {
setIsFlipped(!isFlipped);
});
};
const interpolateFront = animate.current.interpolate({
inputRange: [0, 180],
outputRange: ['0deg', '180deg'],
});
const interpolateBack = animate.current.interpolate({
inputRange: [0, 180],
outputRange: [ '180deg', '360deg'],
});
const rotateFront = {
transform: [
{
rotateY: interpolateFront,
},
],
};
const rotateBack = {
transform: [
{
rotateY: interpolateBack,
},
],
};
and here
<View>
<Animated.View style={[rotateFront], {backfaceVisibility: 'hidden'}}>
<View style={{backgroundColor: 'green', height: 60, width: 60}}/>
</Animated.View>
<Animated.View style={[rotateBack], {backfaceVisibility: 'hidden', position: 'absolute', top: 0}}>
<View style={{backgroundColor: 'blue', height: 60, width: 60}}/>
</Animated.View>
<Button title='Flip' onPress={doAFlip}>Flip</Button>
</View>````
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论