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,
width:140,
borderRadius:5,
justifyContent: 'center',
alignItems: 'center',
},
});
RN Animated透明度动画的更多相关文章
- RN animated组动画
代码: export default class AnimationGroupScene extends Component { constructor() { super() ) ) ) } com ...
- RN animated缩放动画
效果图: 代码: import React, {Component} from 'react'; import { AppRegistry, StyleSheet, Text, Animated, T ...
- RN animated帧动画
效果图: 代码: export default class AnimationFrameScene extends Component { constructor () { super() this. ...
- js实现匀速运动及透明度动画
1.html代码 <body> <div id="container"> <span id="btn"></span& ...
- js动画实现透明度动画
在本次实例中,由于一般主流的浏览器对于透明度opacity最大值为1,但是在IE6最大值是100,此次例子是按主流浏览器的透明度来算的,所以定义的是小数,也可以定义为整数为单位,在运算的时候遇到主流的 ...
- 第一百四十二节,JavaScript,封装库--运动动画和透明度动画
JavaScript,封装库--运动动画和透明度动画 /** yi_dong_tou_ming()方法,说明 * * yi_dong_tou_ming()方法,将一个元素,进行一下动画操作 * 1,x ...
- js简单动画:匀速动画、缓动动画、多物体动画以及透明度动画
主要实现以下几种简单的动画效果(其实原理基本相同): 1.匀速动画:物体的速度固定 2.缓动动画:物体速度逐渐变慢 3.多物体动画 4.透明度动画 效果实现: 1.匀速动画(以物体左右匀速运动为例) ...
- Android 动画-alpha(渐变透明度动画效果)
今天苦于思索应用如何美观,首先从载入页面的第一眼开始,Android动画分为四种:alpha(渐变透明度),scale(渐变尺寸伸缩),translate(画面转换位置移动),rotate(画面转移旋 ...
- Vue系列之 => 使用第三方animated.css动画
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- java获取视频缩略图
近期由于在做一个关于视频播放的项目,需要使用程序自动获取视频文件的缩略图,特写此文供其他人参考,有不清楚之楚可以给我留言. 1.使用工具:ffmpeg, 官网下载地址:http://ffmpeg.or ...
- 设计模式-结构型模式,python组合模式
设计模式上大的方向上分继承和组合,就是类模式和对象模式.此篇的组合模式非继承和组合概念中的组合.桥接 策略 代理 装饰者都用了组合,此组合非彼组合. 组合模式 组合模式(Composite Patte ...
- [Bayes] Point --> Hist: Estimate "π" by R
Verify the Monte Carlo sampling variability of "π". p = π/4 与 所得 0.7854 比较接近,故满足 Central L ...
- 【代码审计】XYHCMS V3.5代码执行漏洞分析
0x00 环境准备 XYHCMS官网:http://www.xyhcms.com/ 网站源码版本:XYHCMS V3.5(2017-12-04 更新) 程序源码下载:http://www.xyhc ...
- SVN 命令行的使用
大多数时候我们用TortoiseSVN作为客户端,其实SVN提供了强大的客户端命令行工具,和Git差不不多. 1. 查看工作副本修改的整体状况. $ svn status ? scratch.c A ...
- 延续(continuation)
首先看下延续的定义: 续延是在运行中被暂停了的程序:即含有计算状态的单个函数型对象.当这个对象被求值时,就会在它上次停下来的地方重新启动之前保存下来的计算 在计算机科学和程序设计领域,延续是计算机程序 ...
- Qt编写的开源帖子集合(懒人专用)
回顾自己学习Qt以来九年了,在这九年多时间里面,从本论坛学习不到不少的东西,今天特意整了一下自己开源过的资源的帖子,整理一起方便大家直接跳转下载,不统计不知道,一统计吓一跳,不知不觉开源了这么多代码, ...
- ARM Linux Oops使用小结(转)
出现Oops消息的大部分错误时因为对NULL指针取值或者因为用了其他不正确的指针值. Oops如何产生的解释如下: 由于处理器使用的地址几乎都是虚拟地址,这些地址通过一个被称为“页表”的结构被 ...
- CentOS和Redhat救援模式
当单用户模式无法修复系统时可以使用救援模式 把系统盘插入光驱重启主机 选择救援模式 默认选择 是否设置网络这里选择否 已读写模式挂载 提示系统挂载/mnt/sysimage如果需要恢复运行 chroo ...
- .NET Core开发日志——简述路由
有过ASP.NET或其它现代Web框架开发经历的开发者对路由这一名字应该不陌生.如果要用一句话解释什么是路由,可以这样形容:通过对URL的解析,指定相应的处理程序. 回忆下在Web Forms应用程序 ...