zoukankan      html  css  js  c++  java
  • RN Animated透明度动画

    主要代码解析:

    如果我们希望吧Animated.Value从0变化到1,把组件位置从60px移动到0px,把不透明度从0编导1,就可以使用style的属性来实现

    <Animated.Text style={{
                        opacity: this.state.fadeAnim,//透明度动画
                        transform: [{
                            translateY: this.state.fadeAnim.interpolate({
                                inputRange: [0, 1],
                                outputRange: [60, 0] //线性插值,0对应60,0.6对应30,1对应0
                            }),
                        },
                            {
                                scale: this.state.fadeAnim
                            },
                        ],
                    }}>
    

    代码:

    import React, {Component} from 'react';
    import {
        AppRegistry,
        StyleSheet,
        Text,
        Animated,
        TouchableOpacity,
        View
    } from 'react-native';
    
    
    export default class AnimationAlphaScene extends Component {
    
        state: {
            fadeAnim: Animated,
            currentAlpha: number,
        };
    
        constructor(props) {
            super(props);
            this.state = {
                currentAlpha: 1.0,
                fadeAnim: new Animated.Value(1.0)
            };
        }
    
        startAnimation() {
            this.state.currentAlpha = this.state.currentAlpha == 1.0 ? 0.0 : 1.0;
            Animated.timing(
                this.state.fadeAnim,
                {toValue: this.state.currentAlpha}
            ).start();
        }
    
        render() {
            return (
                <View style={styles.container}>
    
                    <Animated.Text style={{
                        opacity: this.state.fadeAnim,//透明度动画
                        transform: [{
                            translateY: this.state.fadeAnim.interpolate({
                                inputRange: [0, 1],
                                outputRange: [60, 0] //线性插值,0对应60,0.6对应30,1对应0
                            }),
                        },
                            {
                                scale: this.state.fadeAnim
                            },
                        ],
                    }}>
                        Welcome to React Native!
                    </Animated.Text>
                    <TouchableOpacity onPress={() => this.startAnimation()} style={styles.button}>
                        <Text>启动动画</Text>
                    </TouchableOpacity>
                </View>
            );
        }
    }
    
    const styles = StyleSheet.create({
        container: {
            flex: 1,
            marginTop: 20,
            justifyContent: 'center',
            alignItems: 'center',
        },
        button: {
            marginTop: 20,
            backgroundColor:'#808080',
            height:35,
            140,
            borderRadius:5,
            justifyContent: 'center',
            alignItems: 'center',
    
        },
    
    
    });
    
  • 相关阅读:
    解决ubuntu不能安装g++的问题
    解决VMware虚拟机不能上网的问题
    打开vmvare出现The VMware Authorization Service is not running。
    word2-寻找社交新浪微博中的目标用户
    新浪云计算SAE部署代码过程
    Python如何调用新浪api接口的问题
    work1-英语辅导班在线报名系统
    Mysql对自增主键ID进行重新排序
    如何使用LIBSVM,从安装到基本实例使用
    laravel怎么创建一个简单的blog
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/10183432.html
Copyright © 2011-2022 走看看