想要创建一张翻转卡,但它会赢得翻转

发布于 2025-02-07 16:45:20 字数 1694 浏览 1 评论 0原文

我正在尝试创建一张简单的翻转卡,但是当我按翻转它不会,从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文