主要代码解析:

如果我们希望吧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,
width:140,
borderRadius:5,
justifyContent: 'center',
alignItems: 'center', }, });

RN Animated透明度动画的更多相关文章

  1. RN animated组动画

    代码: export default class AnimationGroupScene extends Component { constructor() { super() ) ) ) } com ...

  2. RN animated缩放动画

    效果图: 代码: import React, {Component} from 'react'; import { AppRegistry, StyleSheet, Text, Animated, T ...

  3. RN animated帧动画

    效果图: 代码: export default class AnimationFrameScene extends Component { constructor () { super() this. ...

  4. js实现匀速运动及透明度动画

    1.html代码 <body> <div id="container"> <span id="btn"></span& ...

  5. js动画实现透明度动画

    在本次实例中,由于一般主流的浏览器对于透明度opacity最大值为1,但是在IE6最大值是100,此次例子是按主流浏览器的透明度来算的,所以定义的是小数,也可以定义为整数为单位,在运算的时候遇到主流的 ...

  6. 第一百四十二节,JavaScript,封装库--运动动画和透明度动画

    JavaScript,封装库--运动动画和透明度动画 /** yi_dong_tou_ming()方法,说明 * * yi_dong_tou_ming()方法,将一个元素,进行一下动画操作 * 1,x ...

  7. js简单动画:匀速动画、缓动动画、多物体动画以及透明度动画

    主要实现以下几种简单的动画效果(其实原理基本相同): 1.匀速动画:物体的速度固定 2.缓动动画:物体速度逐渐变慢 3.多物体动画 4.透明度动画 效果实现: 1.匀速动画(以物体左右匀速运动为例) ...

  8. Android 动画-alpha(渐变透明度动画效果)

    今天苦于思索应用如何美观,首先从载入页面的第一眼开始,Android动画分为四种:alpha(渐变透明度),scale(渐变尺寸伸缩),translate(画面转换位置移动),rotate(画面转移旋 ...

  9. Vue系列之 => 使用第三方animated.css动画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. Xamarin Mono Android实现“再按一次退出程序”

    开始研究Android平台软件编程,Xamarin Mono for Android上手快,跨平台共享代码,代价是bug多多,是一味可口的毒药啊! 环境VS2012 + Xamarin Mono An ...

  2. sencha touch 入门学习资料大全(2015-12-30)

    现在sencha touch已经更新到2.4.2版本了 重新整理一下资料 官方网站:http://www.sencha.com/products/touch/ 在线文档:http://docs.sen ...

  3. [IOI 2000]POJ 1160 Post Office

    Post Office Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22278 Accepted: 12034 Descrip ...

  4. Unity 给Mono脚本添加Try Catch工具

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...

  5. Fiddler如何捕捉DefaultHttpClient的HTTP请求

    实际开发中为了解决Ajax跨域请求问题,会通过一个同域的控制器在服务端代理请求目标的Web API并将结果返回.为了便于调试这类请求,我们希望通过Fiddler可以监控到这些请求.Fiddler官方给 ...

  6. java转换图片压缩生成webp格式

    http://blog.csdn.net/xu_san_duo/article/details/79085718

  7. mapper.xml中转义

    1.用转义字符转义 XML转义字符 < < 小于号 > > 大于号 & & 和 &apos; ’ 单引号 " " 双引号 <i ...

  8. 对Entity Framework Core的一次误会:实体状态不跟踪

    在 Entity Framework 中,当通过 EF 使用 LINQ 查询获取到一个实体(实际得到的是 EF 动态生成的实体类的代理类的实例)时,这个实体的状态默认是被跟踪的.所以,当你修改实体的某 ...

  9. io 流操作hdfs

    hdfs 文件上传 本地   -------->    文件系统对象   -------->    hdfs 文件系统 输入流                                ...

  10. [No0000CF]想有一辈子花不完的钱?从了解“被动收入”开始吧

    我想从理清自己所说被动收入的含义,开始创作此被动收入系列文章. 我更喜欢把被动收入较宽泛地定义为,甚至当你没有主动工作时,仍可赚取的收益.被动收入的另一个名称是剩余收入. 相比之下,当你停止工作时,通 ...