Flutter3D动画Flutter中的Transform可以实现许多酷炫的动画效果,在本篇文章中,将展示如何

以创建Flutter项目默认生成的代码为例来展示3D透视效果。先通过Transform来实现3D效果。代码如下:

为了出于演示的目的,将默认的布局代码通过_defaultApp方法进行了封装,然后仅仅是通过Transfrom来实现3D效果。

上面代码中,通过Transfrom来实现透视效果,而Transfrom是通过Matrix4进行矩阵变换来实现的这个效果。

由于现在的智能手机都有用于图形计算的GPU单元,对于图形的计算与渲染进行了优化,因此即使是渲染3D图形也是非常快的。因此,基本上你看到的手机上的所有图形,都是通过3D的渲染方式来呈现的,即使是2D的图形素材。

通过设置变换矩阵,可以改变我们看到的视觉效果(甚至是3D效果)。通常来讲,矩阵变换包括:平移、旋转、缩放、透视。上面代码中,我们通过identity_matrix创建了一个矩阵,然后应用给Transform。需要注意的是,矩阵变换不满足交换律,因此参数的位置要弄对,当传入矩阵之后,最后的矩阵运算结果会传递给GPU,然后对图像进行渲染。

上面代码实现了透视的效果,也就是,更远的部分,应该看起来更小一些。因此上面的参数里面,会根据距离进行0.001的缩放。

那么0.001这个参数是怎么来的?其实这个数据很随意,可以把这个数据增大或者减小看一下效果,这个数据越大,展现的效果就好像是我们越来越靠近观察对象。

Flutter也提供了一个makePerspectiveMatrix方法进行透视矩阵变换,但是这个方法需要设置一下额外的参数,这些参数我们远远用不到,因此直接使用matrix来完成矩阵变换即可。

同时,上面的代码通过_offset来指定了x轴和轴的旋转。

直接通过GestureDetector来实现手势交互。

接下来实现的效果相对复杂一点,类似翻页效果动画。

第一眼看到这个效果,可能想到的就是,通过Stack来实现,并且每一页都分成上下两部分,每一部分可以绕X轴旋转,旋转之后就会看到下一个页面。

那么该如何用代码来实现呢?可以分成两部分来进行。

那么,在Flutter中,什么样的Widget适合我们来实现这个效果呢?ClipRect和Transform。

接下来定义一个Widget来实现这个功能。

classFlipWidgetextendsStatelessWidget{Widgetchild;FlipWidget({Keykey,this.child}):super(key:key);@overrideWidgetbuild(BuildContextcontext){returnColumn(mainAxisSize:MainAxisSize.min,children:[ClipRect(child:Align(alignment:Alignment.topCenter,heightFactor:0.5,child:child,)),Padding(padding:EdgeInsets.only(top:2.0),),ClipRect(child:Align(alignment:Alignment.bottomCenter,heightFactor:0.5,child:child,)),],);}}这里面的child参数,可以传递任意类型的Widget(text,image等)。运行上面的代码,可以看到如下的效果。

Transform这个Widget组件有一个Matrix4类型的参数transform,这个参数决定了我们将应用何种类型的矩阵变换。同时,Matrix4提供了一个名字为rotationX()的构造方法,这个似乎正是我们需要的,我们把这个应用给页面的上半部分试一下。

@overrideWidgetbuild(BuildContextcontext){returnColumn(mainAxisSize:MainAxisSize.min,children:[Transform(transform:Matrix4.rotationX(pi/4),alignment:Alignment.bottomCenter,child:ClipRect(child:Align(alignment:Alignment.topCenter,heightFactor:0.5,child:child,)),),...],);}运行上面的代码。

显然,这个效果仅仅是把上半部分缩小了,不是我们想要的效果。但是如果额外再指定Matrix4的参数,让row为3,column为2,试一下效果。

Transform(transform:Matrix4.identity()..setEntry(3,2,0.006)..rotateX(pi/4),alignment:Alignment.bottomCenter,child:ClipRect(child:Align(alignment:Alignment.topCenter,heightFactor:0.5,child:child,)),),...

看起来这个是我们需要的效果,上面还一个参数,0.006,这个是怎么来的?其实是试出来的,选一个自己感觉不错的数值就行了。

接下来就是给翻转加上动画了。但是这块可能相对复杂一点。首先,每一页都要理解为有两面(正反面),但是要实现这个效果用代码可能不是很容易,因为我们在手机上看到的图像在任何时刻都只有一面。

我们假设,我们是向上翻转的,那么我们的动画可以分成两部分,第一部分是我们将下半部分向上翻转一半时,这个过程的效果是,当前翻转的页面逐渐消失,而这个页面的下一个页面会逐渐显示。第二部分是,将当前页面继续向上翻转,这个过程的效果是,当前页面会逐渐显示,上半部分的当前页面就是逐渐消失。

THE END
1.From是什么意思问答中心From是什么意思 分类: K12教育 2024-11-17 14:05:11 已浏览:281次 问题描述: From是什么意思,麻烦给回复 2024-11-17 14:05:11 精选答案 风吹过的记忆 已认证 公务员考试,愿你笔下生风,一路过关斩将,金榜题名,前程似... (表示起始点)从…起,始于;(表示开始的时间)从…开始;(表示由某人发出或给出...http://m.gaokaomanfen.com/know/1001921.html
2.transfrom的翻译是:变换中文翻译英文意思,翻译英语atfa tfa[translate] aパッド 垫[translate] ai transferred the proforma invoice for our forwarder in guangzhou. 我在广州转移了形式上的发货票为我们的运输业者。[translate] aS.O.S la fine S.O.S末端[translate] atransfrom transfrom[translate]...http://eyu.zaixian-fanyi.com/fan_yi_14665853
3.TransFromProject张极Jeremy的微博TransFromProject-张极Jeremy 9月16日 17:12 来自vivo S15e #张泽禹张极朱志鑫被袁娅维认可了#优秀的人总会被看到的感谢tia姐 ?收藏 转发 评论 ?1 c +关注 TransFromProject-张极Jeremy 9月16日 08:58 来自vivo S15e #AG夏季赛夺冠# 恭喜AG夺下2024年KPL夏季赛冠军 ...https://weibo.com/7466421871
4.Gradle插件注解javapoet和asm实战在阅读WMRouter和ARouter源码时发现这两个库都用到了自定义注解、自定义gradle插件、Gradle Transfrom API、javapoet和asm库。而我对于这些知识很多我只是了解个大概,或者压根就没听说过。因此ImplLoader这个库主要是用来熟悉这个知识的。当然这个库的实现思路主要参考WMRouter和ARouter。 库的实现原理 用下面这种图概括一下...https://www.imooc.com/article/280634
5.如何使用SQL制作交叉式二维报表?我们之前说TRANSFROM语法如下: TRANSFORMaggfunctionSELECTstatementPIVOTpivotfield [IN (value1[, value2[, ...]])] 以透视表来说,TRANSFORM后的aggfunction,对应的是透视表的值区域,SELECT的statement对应的是透视表的行字段(透视表的行字段肯定是去重归类的),而PIVOT则是对应透视表的列字段。 http://www.360doc.com/content/22/0605/06/13664199_1034584215.shtml
6.csstransform中的矩阵知识刚开始学习css中transfrom的时候,知道它是通过矩阵来完成对元素的控制,移动translate,旋转rotate,缩放scale以及拉伸skew。那时候一看到矩阵就头大了,大学的线性代数都不知道怎么过的,早就还回去了。最近有在看线性代数(还债),通过张鑫旭大神的文章,多少理解了矩阵在transform 中的使用,写这边笔记记录一下。一是用做日...https://www.jianshu.com/p/f6e02a885c36
7.C++TransformListener::lookupTransform方法代码示例示例4: transfromRobotToMapPosition ▲点赞 1▼ voidExplore::transfromRobotToMapPosition(floatx_robot,floaty_robot,float&x_map,float&y_map){ ros::Time now = ros::Time::now(); tf::StampedTransform tfRO; tf_listener_.waitForTransform("/base_link","/odom", now, ros::Duration(1.0)); ...https://vimsky.com/examples/detail/cpp-ex-tf-TransformListener-lookupTransform-method.html
1.TransformDefinition&MeaningMerriamWhat's the difference between 'fascism' and 'socialism'? Popular in Wordplay See All 8 Words with Fascinating Histories 8 Words for Lesser-Known Musical Instruments Birds Say the Darndest Things 10 Words from Taylor Swift Songs (Merriam's Version) ...https://www.merriam-webster.com/dictionary/transform
2.transform’sTransform works to ensure that people of all incomes thrive in a world safe from climate chaos.At Transform, we are dedicated to creating a future where everyone has access to affordable and sustainable transportation options. Join us in building healthihttps://www.transformca.org/
3.TRANSFORMDefinition&MeaningDictionary.com[ verb trans-fawrm; nountrans-fawrm ] Phonetic (Standard)IPA Discover More Other Words From trans·form·a·bleadjective trans·form·a·tiveadjective in·ter·trans·form·a·bleadjective non·trans·form·ingadjective re·trans·formverb (used with object) ...https://www.dictionary.com/browse/transform
4.transformLearn front-end development with high quality, interactive courses from Scrimba. Enroll now!References...transform 属性可以指定为关键字值 none,或者是一个/多个 <transform-function> 值。 https://developer.mozilla.org/zh-CN/docs/Web/CSS/transform
5.Transform详解transfrom由于在机器翻译中,解码过程是一个顺序操作的过程,也就是当解码第 K 个特征向量时,我们只能看到第 K-1 及其之前的解码结果,论文中把这种情况下的multi-head attention叫做masked multi-head attention。transfrom的encoder和decoder整体架构如下: 11.1、Mask ...https://blog.csdn.net/qq_54146731/article/details/134272646
6.transmit是什么意思transmit怎么读中文意思用法transmit 基本解释 vt. 传输, 传染, 传达, 遗传, 发射, 传播 vi. 发射信号, 留传下来 [计] 传送 transmit 词性变化 过去分词:transmitted 现在分词:transmitting 过去式:transmitted 第三人称单数:transmits 中文词源 transmit 传送,发放,播送 trans-,转移,-mit,送出,词源同 emit,mission. ...https://danci.gjcha.com/transmit.html
7.From當代英語文法We use from to show the time or point in time when something starts: Tickets for the concert are on sale from Monday. The finals take place from 1.30 pm on Sunday. We use from to show the level that things begin at, such as numbers or prices: Prices start from £366 per week for...https://dictionary.cambridge.org/zht/%E8%AA%9E%E6%B3%95/%E8%8B%B1%E5%BC%8F%E8%AA%9E%E6%B3%95/origin
8.transfrom的类型有哪些()transfrom的类型有哪些( ) A. scale B. skew C. translate D. rotale E. transition 如何将EXCEL生成题库手机刷题 如何制作自己的在线小题库 > 手机使用 分享 反馈 收藏 举报 参考答案: A B C D 复制 纠错举一反三 新一轮联合国气候变化会议12月2日在()卡托维兹开幕,来自近311个国家的代表将就...https://www.shuashuati.com/ti/4b45c896d51541b8b76f42dd9aa734e3.html?fm=bdbdsbca517dccf897ae291f245785ef991e4
9.GitHubExtract longest transcript or longest CDS transcript from GTF annotation file or gencode transcripts fasta file. - junjunlab/GetTransToolhttps://github.com/junjunlab/GetTransTool
10.CSS:css垂直居中,水平居中,垂直水平居中面试题(五星)2.transfrom实现 .container { width: 300px; height: 300px; position: relative; border: 1px solid #465468; } .inner { width: 100px; height: 100px; position: absolute; margin: auto; left: 50%; transform: translate(-50%, 0); border: ...https://www.nowcoder.com/discuss/452299533674872832
11.技术干货WebRTC系列之GPU方案的探索与落地Transfrom 层实现 Transform 层主要分为三步:输入数据、格式转换、输出数据。输入部分需要关注各种数据类型的输入,做到各种数据输入的兼容;格式转换部分需要满足各种数据类型格式的转换,并且是高效的;输出部分需要关注外部指定的格式要求。 1. 颜色空间的转换YUV 是一种颜色编码方法,主要用在视频、图形处理流水线中。相...https://maimai.cn/article/detail?fid=1689717372&efid=ABA1KQjv_JWvQQ23gnA_MQ
12.transformpython环境快速配置方法python7、hive引用transfrom: 进入hive客户端后,加载上述文件: 1 2 3 ADD ARCHIVE hdfs:///user/tmp/python-env.tgz; ADDFILEhdfs:///user/tmp/test.sh; ADDFILEhdfs:///user/tmp/test_transform.py; 执行hsql: 1 2 3 4 5 6 select transform(id) USING'test.sh'as (id,price1,price2) ...https://www.jb51.net/article/148078.htm
13.unity3d慢mob6454cc6328d1的技术博客Transfrom 2: 例如Transfrom组件: (1)组件实例.DOMove: 平移; (2)组件实例.DOScale: 缩放; (3)组件实例.DORotate 旋转; Tweener常用操作 1: 常用的播放控制函数 组件实例.DOPause(); 暂停一个Tween; 组件实例.DOPlay/DOPlayBackwards/DOPlayForward; 播放 ...https://blog.51cto.com/u_16099177/12549171
14.ECharts图形元素组件(graphic)图形元素的定位和 transfrom 除此以外,可以以 transform 的方式对图形进行平移、旋转、缩放, { type: 'rect', position: [100, 200], // 平移,默认值为 [0, 0]。 scale: [2, 4], // 缩放,默认值为 [1, 1]。表示缩放的倍数。 rotation: Math.PI / 4, // 旋转,默认值为 0。表示旋转的弧度...https://www.w3cschool.cn/echarts_tutorial/echarts_tutorial-3u872dym.html
15.AI大模型研究:NOA和大模型推动ADAS行业巨变2.3.2 三种常见的Transfromer 2.3.3 大模型的根基是Transformer 2.3.4 为什么需要大模型 2.3.5 没有Code,只有NAS 2.3.6 端到端,不添加人工规则 2.3.7 基于Transformer的端到端目标检测 2.3.8 BEV+Transformer是“特征级融合” 2.3.9 已经和即将搭载 AI 大模型的国内车型 ...https://www.dongchedi.com/article/7280338123345871417
16.ImageDT图匠数据的图片拼接技术落地应用,高效实现企业赋能...4. 变换矩阵计算 (transfromation matrix) 通过匹配到的特征点来实现变换矩阵 5. 图像变换 (image warping) 通过图像、变换矩阵,最终获得变换后的图像 当然,这还不算完,在上面所述的技术背后,还涉及到自动拉直、曝光补偿、图片合成、接缝估计等难题。 https://t.m.youth.cn/transfer/index/url/finance.youth.cn/finance_cyxfgsxw/201906/t20190603_11972499.htm
17.Cesium问题汇总1.How to eliminate cesium warning Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true 5.cesium 地图因为transfrom 导致 地图偏移,点击不准的问题 参考文章: 1.解决 cesium 地图因为transfrom 导致 地图偏移,点击不准的问题...https://bibichuan.github.io/posts/329aea90.html
18.NovelCentromericLocioftheWineandBeerYeastDekkera...(1960–2014). supporting information novel centromeric loci of the wine and beer yeastdekkera bruxellensis cen1andcen2 showing 1/16:s1 fig.tif figshare analysis ofcen1andcen2plasmids isolated from yeast transfromants through shuttling toe.coli. plasmids native forms and their restriction pattern ...http://dx.doi.org/10.1371/journal.pone.0161741
19.transfromtutorialYou can use theinverted()method to create a transform which will take you from display to data coordinates: In [41]:inv=ax.transData.inverted()In [42]:type(inv)Out[42]:<class'matplotlib.transforms.CompositeGenericTransform'>In [43]:inv.transform((335.175,247.))Out[43]:array([5.,0.]...https://matplotlib.org/1.3.1/users/transforms_tutorial.html
20.ChristianTranshumanistAssociation:Faith,Technology,and...Since our formation over seven years ago, the Christian Transhumanist Association has been working hard to advance the conversation between Christianity and the leading edges of technological thought. From our first major action funding the Embrace Infant Warmer project—uniting our values of technology...http://www.christiantranshumanism.org/blog