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 ...
随机推荐
- [IR] Open Source Search Engines
From:http://blog.csdn.net/xum2008/article/details/8740063 本文档是对现有的开源的搜索引擎的一个简单介绍 1. Lucene Lucene ...
- python 爬虫练习
bs去除特定标签. # url import easygui as g import urllib.request from bs4 import BeautifulSoup import os im ...
- 关于H5页面在iPhoneX适配(转)
1. iPhoneX的介绍 屏幕尺寸 我们熟知的iPhone系列开发尺寸概要如下: △ iPhone各机型的开发尺寸 转化成我们熟知的像素尺寸: △ 每个机型的多维度尺寸 倍图其实就是像素尺寸和开 ...
- C#自定义无边框MessageBox窗体
C#自定义无边框MessageBox窗体 本例子中制作一个无边框的MessageBox窗体 展示效果: 窗体设计 1.添加一个窗体继承原生Form public partial class Messa ...
- Maven & Gradle 如何从中央仓库下载Jar包
https://mvnrepository.com/ maven 中央仓库 gradle可以轻松的完成Android项目对第三方jar包文件的依赖下载,再也不需要我们手动下载jar包,然后拷贝到 ...
- 还不错的MUI技术文档
https://blog.csdn.net/xin724/article/details/81939176
- Solr-全文检索工具简介
一.Solr的简介 Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务.Solr可以独立运行在Jetty.Tomcat等这些Servlet容器中.都是W ...
- python-and和 or用法
python中的逻辑运算 and和or执行逻辑运算,但是它们不会返回bool值,而是返回它们进行比较的值之一 and >>> 1 and 2 取2 >>>1 and ...
- xdebug的配置
第一步,让xdebug在php环境中生效 下载xdebug http://www.xdebug.org/download.php 这里会出现针对PHP各种版本的下载.找到适合你自己的版本,此处值得注意 ...
- Some untracked working tree files would be overwritten by checkout. Please move or remove them before you can checkout. View them
Some untracked working tree files would be overwritten by checkout. Please move or remove them befor ...