react native中使用Animated实现三张图片动态旋转效果

react native中使用Animated实现三张图片动态旋转效果

效果示例图

在这里插入图片描述
在这里插入图片描述

示例代码

import React, {useEffect, useRef} from 'react';
import {Animated, StyleSheet, View} from 'react-native';
import {pxToPd} from '../../common/js/device';

const TestShowCard = () => {
  const rotationValue = useRef(new Animated.Value(0)).current;

  const firstCardRotation = '0deg';
  const secondCardRotation = rotationValue.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '-15deg'],
  });
  const thirdCardRotation = rotationValue.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '15deg'],
  });

  useEffect(() => {
    Animated.timing(rotationValue, {
      toValue: 1,
      duration: 1000,
      useNativeDriver: true,
    }).start();
    return () => {};
  }, []);

  return (
    <>
      <View style={styles.container}>
        <View style={styles.dynCard}>
          <Animated.View
            style={[
              styles.cardItem,
              {transform: [{rotate: thirdCardRotation}]},
            ]}></Animated.View>
          <Animated.View
            style={[
              styles.cardItem,
              {transform: [{rotate: secondCardRotation}]},
            ]}></Animated.View>
          <Animated.View
            style={[
              styles.cardItem,
              {transform: [{rotate: firstCardRotation}]},
            ]}></Animated.View>
        </View>
      </View>
    </>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  dynCard: {
    width: pxToPd(174),
    height: pxToPd(203),
    position: 'relative',
    marginTop: pxToPd(200),
    marginLeft: pxToPd(100),
  },
  cardItem: {
    width: '100%',
    height: '100%',
    borderColor: 'blue',
    borderWidth: pxToPd(1),
    borderStyle: 'solid',
    position: 'absolute',
    backgroundColor: 'white',
  },
});

export default TestShowCard;

相关推荐

  1. css动画旋转效果实现

    2024-03-11 12:16:03       37 阅读
  2. React使用动态图标

    2024-03-11 12:16:03       41 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-11 12:16:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-11 12:16:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-11 12:16:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-11 12:16:03       20 阅读

热门阅读

  1. 谈谈Pytorch中的dataset

    2024-03-11 12:16:03       20 阅读
  2. 流量池增长(3)

    2024-03-11 12:16:03       23 阅读
  3. 在github上配置使用CI

    2024-03-11 12:16:03       25 阅读
  4. 计算机网络概述(接入网和物理媒体)

    2024-03-11 12:16:03       19 阅读
  5. Oracle Linux 8.9 安装 Python 3.11.8 和 Miniconda

    2024-03-11 12:16:03       26 阅读
  6. ocr关键信心提取数据集

    2024-03-11 12:16:03       25 阅读
  7. Python实战:Python常用IDE选择

    2024-03-11 12:16:03       30 阅读
  8. FFmpeg对H246进行编解码的实现

    2024-03-11 12:16:03       25 阅读
  9. 突破编程_C++_设计模式(外观模式)

    2024-03-11 12:16:03       21 阅读
  10. Android 14.0 屏蔽Launcher3桌面app图标的长按功能

    2024-03-11 12:16:03       24 阅读
  11. 3级考题(2)(c++)

    2024-03-11 12:16:03       23 阅读
  12. 计算机网络

    2024-03-11 12:16:03       23 阅读
  13. 企业数字化转型应该如何做

    2024-03-11 12:16:03       24 阅读