当前位置:网站首页>[harmony OS] [arkui] ETS development graphics and animation drawing
[harmony OS] [arkui] ETS development graphics and animation drawing
2022-06-25 03:57:00 【Huawei Developer Forum】
ArkUI】ets Development Graphics and animation
Preface : We've done it before Harmony ArkUI Use ets To realize the learning of basic page layout and data connection , This time we will draw some pictures and animations on the basis of the original . This article is based on HarmonyOS Based on the official website TS Extended declarative development paradigm document , Based on drawing and animation . Therefore, the author integrates the original text , Extract the key points , So that it can be easily presented to the reader , I hope it can help you quickly understand Harmony Of ETS Development , Learn to draw simple graphics and animation . A link to the original text will be posted at the end of this article .
First, let's talk about the general idea , We want to use component tools to draw basic geometry , Custom drawing geometry , Add animation effects to graphics , And the transition animation of the page . Therefore, the author divides the realization of the whole function into two steps , Graphics and animation , This is roughly the same as the original .
1. Graph drawing .
In previous studies , The project we have established , The page layout is complete , Let's draw graphics on this basis .FoodDetail In the food composition table on the page , Add a circular icon before the name of each ingredient as the ingredient label .
1) Draw basic figures . establish Circle Components , Add a circular icon in front of each content component as a label . modify FoodDetail Page ContentTable In the component IngredientItem Method , Add... Before the component name Circle. The label color of each component is different in build In the method , call IngredientItem, For each Circle Fill in different colors .

open previewer Or simulator to see the effect

2) Draw custom graphics . stay pages Create a new one under the folder eTS page Logo.ets. stay Logo.ets Created in Logo Component, establish Flex The component is the root node , establish Shape Components for Flex Child components . Fill the page with gradients . Set to linear gradient , The offset angle is 180deg, Three stage gradient #BDE895 -->95DE7F --> #7AB967.

open previewer Or simulator to see the effect

3) Draw a route Path, Set its draw command . The fill color is white .

4) stay Shape Draw the second... Within the component Path. Second Path The background color of is gradient .Path The drawing command of is relatively long , You can use it as a member variable of a component , adopt this call . Complete the application Logo The draw .Shape Combined three Path Components .

open previewer Or simulator to see the effect

2. Animation .
In the last part, we have learned the drawing of ordinary graphics and custom graphics , In this part, we will add animation effects to the implementation on the basis of graphic rendering , Let the graph move , This is animation .
The animation function is divided into component animation and inter page animation , In this section, we mainly complete two animation effects :Logo The fade out and zoom in effect of the icon is the same as the transition animation effect of the food list page and the food details page .
1) Flash screen animation . The expected effect of flash screen animation is , Get into Logo After the page ,animateTo The animation effect starts playing automatically . call Shape Of onAppear Method , Animate it explicitly . establish opacity and scale Numeric member variables , With a decorator @State modification . Indicates that it is stateful data , That is, the change will trigger the refresh of the page .


2) Set up animateTo The animation curve of curve.Logo The acceleration curve is slow first and then fast , Use Bezier curves cubicBezier,cubicBezier(0.4, 0, 1, 1). Use interpolation to calculate , Import first curves modular .

3) The animation duration is 1s, Time delay 0.1s Start playing , Set the display dynamic effect event The closure function of , Realization Logo Fade out and zoom in . Freeze frame after the flash screen animation is played 1s, Get into FoodCategoryList page . Set up animateTo Of onFinish Callback interface , Call timer Timer Of setTimeout Interface delay 1s after , call router.replace, Show FoodCategoryList page .

open previewer Or simulator to see the effect

4) Page transition animation . Shared element transition between food classification list page and food details page , Click FoodListItem/FoodGridItem after , The food thumbnail will enlarge , Jump with the page , Go to the big picture on the food details page . introduce curves modular . stay FoodListItem Of Image Set... On the component autoResize by false, because image By default, the component will be displayed according to the final display area , To adjust the size of the image source , To optimize picture rendering performance .


5) Set up FoodDetail Page FoodImageDisplay Of Image Component's shared element transition method (sharedTransition). The setting method is the same as above .

open previewer Or simulator to see the effect

above , This time's content sharing , thank you !
Link to original :
https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ui-ts-drawing-feature-0000001192705721
边栏推荐
- 佐喃社区
- Crawler crawls Sina Weibo data
- Now, the ear is going into the metauniverse
- 发布功能完成02《ivx低代码签到系统制作》
- Xidian AI ranked higher than Qingbei in terms of AI majors, and Nantah ranked the first in China in 2022 in terms of soft science majors
- Tianshu night reading notes - 8.4 diskperf disassembly
- The sign in function completes 03 "IVX low code sign in system production"
- Deveco studio 3.0 editor configuration tips
- Why can banana be a random number generator? Because it is the "king of radiation" in the fruit industry
- 【组队学习】SQL编程语言笔记——Task04
猜你喜欢

Lao Ye's blessing

威马招股书拆解:电动竞争已结束,智能排位赛刚开始

ICML 2022 | ByteDance AI Lab proposes a multimodal model: x-vlm, learning multi granularity alignment of vision and language

AI越进化越跟人类大脑像!Meta找到了机器的“前额叶皮层”,AI学者和神经科学家都惊了...

The release function completed 02 "IVX low code sign in system production"

腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...

X86 CPU, critical! The latest vulnerability has caused heated discussion. Hackers can remotely steal keys. Intel "all processors" are affected

后台页制作01《ivx低代码签到系统制作》

Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality

Amazon's other side in China
随机推荐
DevEco Studio 3.0编辑器配置技巧篇
Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
The programmer reality show is coming again! Hulan, as the host, carried the lamp to fill the knowledge. The SSS boss had a bachelor's degree in pharmacy. Zhu Jun and Zhang Min from Tsinghua joined th
Disassembly of Weima prospectus: the electric competition has ended and the intelligent qualifying has just begun
【Harmony OS】【ARK UI】ETS 上下文基本操作
OpenSUSE installation pit log
Datetimeformat is invalid under @requestbody
BGP biplane architecture
AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
OpenSUSE environment PHP connection Oracle
威马招股书拆解:电动竞争已结束,智能排位赛刚开始
Tutorial on installing SSL certificates in Microsoft Exchange Server 2007
Tencent's open source project "Yinglong" has become a top-level project of Apache: the former long-term service wechat payment can hold a million billion level of data stream processing
存算一体芯片离普及还有多远?听听从业者怎么说 | 对撞派 x 后摩智能
你真的需要自动化测试吗?
AI自己写代码让智能体进化!OpenAI的大模型有“人类思想”那味了
Create SQLite table with shell script and add SQL statement -- General
PHP代码审计1—PHP.ini的那些事
Lao Ye's blessing