React-Native 學(xué)習(xí)Animated -1

//Animated.timing實(shí)現(xiàn)view的位置移動(dòng)
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Animated, TouchableHighlight, View, Text} from 'react-native';

var xx = 0;
class RnAnimatedView extends Component {
    constructor(props) {
        super(props);
        this.state= {
            left: new Animated.Value(0),
        }
    }
    render() {
        let animView = (
            //這里需要使用transform, rotateX被包含在transform的屬性中。
            //interpolate很特殊,可以插入一些參數(shù)
            <Animated.View style={[{marginTop: 20, backgroundColor: '#ff00ff'}, {left: this.state.left.interpolate({
                //inputRange和outputRange定義了旋轉(zhuǎn)的范圍,可以調(diào)整參數(shù)看看兩者有什么聯(lián)系
                inputRange: [0, 1],
                outputRange: [0, 200],
            })}]}>
                <Text>我要開始移動(dòng)了</Text>
            </Animated.View>
        );
        return(
            <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
                <TouchableHighlight onPress={this.animation}>
                    <Text>點(diǎn)我開始動(dòng)畫</Text>
                </TouchableHighlight>
                {animView}
            </View>
        )

    }
    animation= () => {
        xx = xx === 0 ? 1 : 0;
        let timing = Animated.timing;
        timing(this.state.left, {
            toValue: xx,
            duration: 1000,
        }).start();
    }
}
AppRegistry.registerComponent('RnAnimatedView', () => RnAnimatedView);
Untitled3.gif
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容