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;
相关推荐
Slow菜鸟10 分钟前
ES5 vs ES6:JavaScript 演进之路
前端·javascript·es6
Jiaberrr2 小时前
Vue 3 中搭建菜单权限配置界面的详细指南
前端·javascript·vue.js·elementui
科科是我嗷~2 小时前
【uniapp】textarea maxlength字数计算不准确的问题
javascript·uni-app·html
懒大王95272 小时前
uniapp+Vue3 组件之间的传值方法
前端·javascript·uni-app
烛阴2 小时前
秒懂 JSON:JavaScript JSON 方法详解,让你轻松驾驭数据交互!
前端·javascript
拉不动的猪3 小时前
刷刷题31(vue实际项目问题)
前端·javascript·面试
zeijiershuai3 小时前
Ajax-入门、axios请求方式、async、await、Vue生命周期
前端·javascript·ajax
拉不动的猪3 小时前
刷刷题30(vue3常规面试题)
前端·javascript·面试
狂炫一碗大米饭3 小时前
面试小题:写一个函数实现将输入的数组按指定类型过滤
前端·javascript·面试
最胖的小仙女3 小时前
通过动态获取后端数据判断输入的值打小
开发语言·前端·javascript