【问题标题】:how to make this animate with react-native?如何用 react-native 制作这个动画?
【发布时间】:2016-09-30 05:01:37
【问题描述】:

How to make this transform with React-Native?

我想要这个静态位置

constructor(props) {
        super(props);
        this.state={
            loaded:false,

            transform:[{ perspective: 0 },
                      { translateX: width },
                      { rotateY: '0deg'}],
            isMenuOpen:false,
        }
    }

动画到这个位置

Animated.timing(
                this.state.transform,
                {toValue:[{ perspective: 850 },
                          { translateX: -width * 0.24 },
                          { rotateY: '60deg'}]},
            ).start();

动画代码怎么写?

【问题讨论】:

    标签: animation react-native transform


    【解决方案1】:

    您不能以这种方式使用 Animated... 看Animated 链接您需要做的下一件事:

    <MyComponent style={{
              transform:[{ perspective: this.state.anim.interpolate({
                                        inputRange: [0, 1],
                                        outputRange: [0, 850],
                        })},
                         { translateX: this.state.anim.interpolate({
                                         inputRange: [0, 1],
                                         outputRange: [width, -width * 0.24],
                        })},
                         { rotateY: this.state.anim.interpolate({
                                         inputRange: [0, 1],
                                         outputRange: ["0deg", "60deg"],
                        })}],
           }],
         }}/>
    

    ------////------

                Animated.timing(this.state.anim, {
                  toValue: 1
                }),
    

    --------////--------

    constructor(props) {
            super(props);
            this.state={
                anim: AnimateValue(0)
            }
        }
    

    【讨论】:

    • 这是正确的方向,但您可以通过仅重用 1 个 Animated.Value 来简化这一点(假设您希望在 3 个变换上使用相同类型的定时动画)。
    • @simcha 出现错误,如何解决?谢谢!用“perspective”键转换不能为零:{“perspective”:0}rnplay.org/apps/pBrrUg
    • @JeanRegisser,你能帮我解决问题吗?这里,rnplay.org/apps/pBrrUg,非常感谢!
    • 我解决了!谢谢你们 ! @JeanRegisser,@Simcha。 rnplay.org/apps/pBrrUg
    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多