鱼C论坛

 找回密码
 立即注册
查看: 4073|回复: 0

[技术交流] RN动画制作之放大效果

[复制链接]
发表于 2017-8-10 08:37:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import React, { Component } from 'react';
  2. import {
  3.   AppRegistry,
  4.   View,
  5.   Text,
  6.   TouchableHighlight,
  7.   Button,
  8.   Animated,
  9.   ImageBackground
  10. } from 'react-native';

  11. export default class myreact extends Component {
  12.   constructor(props) {
  13.     super(props);
  14.     this.state = {
  15.       action:1,
  16.       a:new Animated.Value(1)
  17.       }
  18.    
  19.     };
  20.   render() {   
  21.     return (
  22.       <ImageBackground source={require('./img/0.jpg')}
  23.         style={{justifyContent: 'center',alignItems: 'center' }}
  24.       >
  25.       <Button
  26.       onPress={()=>{
  27.         this.setState({action:this.state.a})
  28.         Animated.timing(
  29.           this.state.a,
  30.          
  31.           {
  32.             toValue: 10,
  33.           duration: 5000,

  34.           }
  35.          
  36.     ).start()
  37.       }
  38.       }
  39.       title="放大"
  40.       color="#841584"
  41.       />
  42.       <Animated.View  
  43.         style={{marginTop: 100,height: 20,width: 20,
  44.         backgroundColor: 'red',
  45.         transform:[{scale:this.state.action}]}}        
  46.       >
  47.       </Animated.View>
  48.       
  49.       </ImageBackground>
  50.     );
  51.   }
  52. }
  53. AppRegistry.registerComponent('myreact', () => myreact);
复制代码

今天再学个新标签ImageBackground,可以放背景图。还是跟上次代码差不多就是改变transform里的scale属性,这次把初始状态设定为1,点击按钮后让他放大10倍,接下来效果图:
jdfw.gif

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-6 02:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表