当我的密码错误时,我想摇动View以下的数字.

它应该是从第10位到第20位的translateX,持续4次1秒.

位置10(我指的是View的X位置)

startShake = () => {
   Animated.loop(
       Animated.sequence([
         Animated.timing(this.animatedValue, {toValue: 1, duration: 150, easing: Easing.linear, useNativeDriver: true}),
         Animated.timing(this.animatedValue, {toValue: -1, duration: 300, easing: Easing.linear, useNativeDriver: true}),
         Animated.timing(this.animatedValue, {toValue: 0, duration: 150, easing: Easing.linear, useNativeDriver: true}),
       ])
   ).start();
}

<Animated.View style={{transform: [{
    translateX: this.animatedValue.interpolate({
        inputRange: [0, 0],
        outputRange: [0, 0]
     })
  }]
}}>

</Animated.View>

推荐答案

谢谢你的回答.

我刚刚解决了用以下代码编辑代码的问题

  constructor(props) {
    super(props)
    this.shakeAnimation = new Animated.Value(0);
  }

 startShake = () => {
    Animated.sequence([
      Animated.timing(this.shakeAnimation, { toValue: 10, duration: 100, useNativeDriver: true }),
      Animated.timing(this.shakeAnimation, { toValue: -10, duration: 100, useNativeDriver: true }),
      Animated.timing(this.shakeAnimation, { toValue: 10, duration: 100, useNativeDriver: true }),
      Animated.timing(this.shakeAnimation, { toValue: 0, duration: 100, useNativeDriver: true })
    ]).start();
 }

 <Animated.View style={{ transform: [{translateX: this.shakeAnimation}] }}>  

 </Animated.View>

React-native相关问答推荐

如何在使用嵌套的堆栈导航器在选项卡之间导航后弹出到堆栈顶部?

为什么我的expoav视频不会自动播放?

使用下拉菜单时react 本机react-native-dropdown-select-list,它会将下面的项目向下移动.如何阻止这种情况发生

错误发生意外错误:https://registry.yarnpkg.com/react-native-template-react-native-template-typescript:未找到

如何获取 iOS 版本?

Invariant Violation:requireNativeComponent: "RNCWebView" was not found in the UIManager

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

如何在 React Native For Android 中删除启动画面后的白屏

React-Native 应用程序的 Jest 测试 Animated.View

如何从 React Native-App 中的 res/drawable-folder 加载图像?

react-native run-android 构建错误':app:generateDebugBuildConfig'

如何将 Leaflet.js 与 react-native 一起使用

React Native vs Swift/Objective-C/Java Native

horizontal水平 FlatList 前后的间距

设置 react-native 元素时使用特定的包名称

是否可以将 Material UI 库与 React Native 一起使用?

如何在react-native中将文本放置在图像上?

React Native 多行TextInput,文本居中

React Native 项目,有时使用 expo start 获得连接 ECONNREFUSED 127.0.0.1:19001

为什么 this.state 在react-native中未定义?