我try 使用转换X和转换Y转换视图时出现此错误

  • ExceptionsManager.js:173无法将类型为NSMuable数组的JSON值‘({转换X=0;转换Y=120;})’转换为CATransform3D.必须 for each Transform对象恰好指定一个属性.

    Const BouneInUp:fc=({Child,teddyear})=>{ Const bouneValue=new Animated.Value(120); Const shakeValue=new Animated.Value(0);

    const animate = useCallback(() => {
      Animated.sequence([
        Animated.delay(300),
        Animated.spring(bounceValue, {
          useNativeDriver: true,
          toValue: -10,
          velocity: 3,
          friction: 8,
        }),
        Animated.sequence([
          Animated.timing(shakeValue, { toValue: 10, duration: 100, useNativeDriver: true }),
          Animated.timing(shakeValue, { toValue: -10, duration: 100, useNativeDriver: true }),
          Animated.timing(shakeValue, { toValue: 10, duration: 100, useNativeDriver: true }),
          Animated.timing(shakeValue, { toValue: 0, duration: 100, useNativeDriver: true }),
        ]),
      ]).start();
    }, [bounceValue, shakeValue]);
    
    useEffect(() => {
      animate();
    }, [teddyBear.id]);
    
    return (
      <Animated.View style={[styles.subView, { transform: [{ translateY: bounceValue, translateX: shakeValue }] }]}>
        {children}
      </Animated.View>
    );
    

    };

推荐答案

这只是一个类型错误 你可以试试

transform: [
{ translateY: y-value},
 { translateX: x-value}
]

React-native相关问答推荐

React Native 组件中两次使用map的问题

从 React 原生 Js 代码调用 Android Native UI 组件方法

你使用 react native 应该学习 react.js 吗?

如何将谷歌反向地理编码与 React Native Expo 结合使用?

RNFS.exists() 总是返回 TRUE

React Redux 使用带有连接组件的 HOC

React-native 组件的 elevation样式导致的阴影

如何在获取请求中传递 POST 参数?

React Native - ScrollView 中的 ListView 分页?

React Native - 如何判断 UI/元素?

从堆栈导航器中删除屏幕

如何使用 Typescript 在无状态组件上设置 navigationOptions

React Native 创建自定义组件/库

组件div的视图配置 getter 回调必须是一个函数(收到 undefined)

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.

为什么,确切地说,我们需要 React.forwardRef?

使用来自另一个页面的 fetch 调用函数返回结果值

如何用 Realm 元素文件组织 React Native?

如何在 react-native 中为在后台杀死的 android 应用程序保持状态

React Native:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败