<legend id='80hMg'><style id='80hMg'><dir id='80hMg'><q id='80hMg'></q></dir></style></legend>

        <tfoot id='80hMg'></tfoot>

        <i id='80hMg'><tr id='80hMg'><dt id='80hMg'><q id='80hMg'><span id='80hMg'><b id='80hMg'><form id='80hMg'><ins id='80hMg'></ins><ul id='80hMg'></ul><sub id='80hMg'></sub></form><legend id='80hMg'></legend><bdo id='80hMg'><pre id='80hMg'><center id='80hMg'></center></pre></bdo></b><th id='80hMg'></th></span></q></dt></tr></i><div id='80hMg'><tfoot id='80hMg'></tfoot><dl id='80hMg'><fieldset id='80hMg'></fieldset></dl></div>

        <small id='80hMg'></small><noframes id='80hMg'>

          <bdo id='80hMg'></bdo><ul id='80hMg'></ul>
      1. React Native:如何为图像的旋转设置动画?

        时间:2023-10-13

      2. <legend id='4A8F5'><style id='4A8F5'><dir id='4A8F5'><q id='4A8F5'></q></dir></style></legend>
      3. <tfoot id='4A8F5'></tfoot>
              <bdo id='4A8F5'></bdo><ul id='4A8F5'></ul>
            • <i id='4A8F5'><tr id='4A8F5'><dt id='4A8F5'><q id='4A8F5'><span id='4A8F5'><b id='4A8F5'><form id='4A8F5'><ins id='4A8F5'></ins><ul id='4A8F5'></ul><sub id='4A8F5'></sub></form><legend id='4A8F5'></legend><bdo id='4A8F5'><pre id='4A8F5'><center id='4A8F5'></center></pre></bdo></b><th id='4A8F5'></th></span></q></dt></tr></i><div id='4A8F5'><tfoot id='4A8F5'></tfoot><dl id='4A8F5'><fieldset id='4A8F5'></fieldset></dl></div>

                <small id='4A8F5'></small><noframes id='4A8F5'>

                    <tbody id='4A8F5'></tbody>
                  本文介绍了React Native:如何为图像的旋转设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  旋转是一种样式变换,在 RN 中,您可以像这样旋转东西

                  Rotation is a style transform and in RN, you can rotate things like this

                    render() {
                      return (
                        <View style={{transform:[{rotate: '10 deg'}]}}>
                          <Image source={require('./logo.png')} />
                        </View>
                      );
                    }
                  

                  但是,要在 RN 中制作动画,您必须使用数字,而不是字符串.你还能在 RN 中为变换设置动画,还是我必须想出某种 sprite sheet 并以某些 fps 更改 Image src?

                  However, to animate things in RN, you have to use numbers, not strings. Can you still animate transforms in RN or do I have to come up with some kind of sprite sheet and change the Image src at some fps?

                  推荐答案

                  您实际上可以使用 interpolate 方法为字符串设置动画.interpolate 采用一系列值,通常 0 到 1 适用于大多数情况,并将它们插入到一系列值中(这些可以是字符串、数字,甚至是返回值的函数).

                  You can actually animate strings using the interpolate method. interpolate takes a range of values, typically 0 to 1 works well for most things, and interpolates them into a range of values (these could be strings, numbers, even functions that return a value).

                  你要做的是获取一个现有的 Animated 值并将其传递给 interpolate 函数,如下所示:

                  What you would do is take an existing Animated value and pass it through the interpolate function like this:

                  spinValue = new Animated.Value(0);
                  
                  // First set up animation 
                  Animated.timing(
                      this.spinValue,
                    {
                      toValue: 1,
                      duration: 3000,
                      easing: Easing.linear, // Easing is an additional import from react-native
                      useNativeDriver: true  // To make use of native driver for performance
                    }
                  ).start()
                  
                  // Next, interpolate beginning and end values (in this case 0 and 1)
                  const spin = this.spinValue.interpolate({
                    inputRange: [0, 1],
                    outputRange: ['0deg', '360deg']
                  })
                  

                  然后像这样在你的组件中使用它:

                  Then use it in your component like this:

                  <Animated.Image
                    style={{transform: [{rotate: spin}] }}
                    source={{uri: 'somesource.png'}} />
                  

                  如果你想在循环中进行旋转,那么在 Animated.loop

                  In case if you want to do the rotation in loop, then add the Animated.timing in the Animated.loop

                  Animated.loop(
                   Animated.timing(
                     this.spinValue,
                     {
                      toValue: 1,
                      duration: 3000,
                      easing: Easing.linear,
                      useNativeDriver: true
                     }
                   )
                  ).start();
                  

                  这篇关于React Native:如何为图像的旋转设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在画布中旋转一张图像? 下一篇:CSS 在容器内旋转元素

                  相关文章

                  最新文章

                1. <small id='47DKZ'></small><noframes id='47DKZ'>

                  <legend id='47DKZ'><style id='47DKZ'><dir id='47DKZ'><q id='47DKZ'></q></dir></style></legend>

                    <i id='47DKZ'><tr id='47DKZ'><dt id='47DKZ'><q id='47DKZ'><span id='47DKZ'><b id='47DKZ'><form id='47DKZ'><ins id='47DKZ'></ins><ul id='47DKZ'></ul><sub id='47DKZ'></sub></form><legend id='47DKZ'></legend><bdo id='47DKZ'><pre id='47DKZ'><center id='47DKZ'></center></pre></bdo></b><th id='47DKZ'></th></span></q></dt></tr></i><div id='47DKZ'><tfoot id='47DKZ'></tfoot><dl id='47DKZ'><fieldset id='47DKZ'></fieldset></dl></div>

                        <bdo id='47DKZ'></bdo><ul id='47DKZ'></ul>
                    1. <tfoot id='47DKZ'></tfoot>