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 ...
随机推荐
- 安卓开发笔记——个性化TextView(新浪微博)
这几天在仿写新浪微博客户端,在处理微博信息的时候需要处理关键字高亮和微博表情,查了一些资料,决定记录点东西 先来看下效果图: 像以上这种#话题#,@XXX昵称,HTTP:网页链接等元素,在微博里是被高 ...
- @Autowired注入为null问题分析
题说明 最近看到Spring事务,在学习过程中遇到一个很苦恼问题 搭建好Spring的启动环境后出现了一点小问题 在启动时候却出现[java.lang.NullPointerException] 不过 ...
- Ubuntu中apt与apt-get命令的区别
https://blog.csdn.net/taotongning/article/details/82320472
- [OpenCV] Samples 14: kalman filter
Ref: http://blog.csdn.net/gdfsg/article/details/50904811 #include "opencv2/video/tracking.hpp&q ...
- iOS手机淘宝加入购物车动画分析
本文转载至 http://www.jianshu.com/p/e77e3ce8ee24 1.最终效果 仿淘宝动画 2.核心代码 _cartAnimView=[[UIImageView alloc] i ...
- 【laravel5.6】 laravel中间件内生成参数并且传递到控制器的2种方法
中间件方法: /** * 自定义中间件: * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return ...
- css - Grid网格布局
.wrapper{ display: grid; grid-template-columns: 100px 100px 100px; grid-template-rows: 100px 100px 1 ...
- lsass 病毒手动清除方法
病毒症状进程里面有2个lsass.exe进程,一个是system的,一个是当前用户名的(该进程为病毒).双击D:盘打不开,只能通过右击选择打开来打开.用kaspersky扫描可以扫描出来,并且可以杀掉 ...
- db2 reorg table failed处理
概要: 当对一个表的结构进行改变后,需要reorg表,重新组织其目录统计信息,为数据库的访问计划提供信息,以便高效执行对其的操作. 对表作reorg操作,发生错误,通过db2 "? sql0 ...
- 开发人员如何从官网首页进入下载JDK历史版本
就是下面的这篇文章,好心好意提交到百度经验,希望给需要的人一个帮助,结果被拒,说有广告.呵呵,oracle和java真的需要在你百度上面做广告吗?倒是能理解,可能是外行人做的,只是看到链接就拒了,但是 ...