介紹
本篇Codelab使用動(dòng)畫(huà)樣式,實(shí)現(xiàn)幾種常見(jiàn)動(dòng)畫(huà)效果:平移、旋轉(zhuǎn)、縮放以及透明度變化。
相關(guān)概念
- [自定義組件]:自定義組件是用戶根據(jù)業(yè)務(wù)需求,將已有的組件組合,封裝成的新組件,可以在工程中多次調(diào)用,從而提高代碼的可讀性。
- [動(dòng)畫(huà)樣式]:組件支持動(dòng)態(tài)的旋轉(zhuǎn)、平移、縮放效果,可在style或css中設(shè)置。
環(huán)境搭建
軟件要求
- [DevEco Studio]版本:DevEco Studio 3.1 Release及以上版本。
- OpenHarmony SDK版本:API version 9及以上版本。
硬件要求
- 開(kāi)發(fā)板類型:[潤(rùn)和RK3568開(kāi)發(fā)板]。
- OpenHarmony系統(tǒng):3.2 Release及以上版本。
環(huán)境搭建
完成本篇Codelab我們首先要完成開(kāi)發(fā)環(huán)境的搭建,本示例以RK3568開(kāi)發(fā)板為例,參照以下步驟進(jìn)行:
- [獲取OpenHarmony系統(tǒng)版本]:標(biāo)準(zhǔn)系統(tǒng)解決方案(二進(jìn)制)。以3.2 Release版本為例:
- 搭建燒錄環(huán)境。
- [完成DevEco Device Tool的安裝]
- [完成RK3568開(kāi)發(fā)板的燒錄](méi)
- 搭建開(kāi)發(fā)環(huán)境。
代碼結(jié)構(gòu)解讀
本篇Codelab只對(duì)核心代碼進(jìn)行講解,對(duì)于完整代碼,我們會(huì)在gitee中提供。
`HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿`
├──entry/src/main/js // 代碼區(qū)
│ └──MainAbility
│ ├──common
│ │ └──images
│ │ └──ic_windmill.png // 風(fēng)車圖標(biāo)
│ ├──component
│ │ └──animatedCards
│ │ ├──animatedCards.css // 自定義動(dòng)畫(huà)組件樣式
│ │ ├──animatedCards.hml // 自定義動(dòng)畫(huà)組件頁(yè)面
│ │ └──animatedCards.js // 自定義動(dòng)畫(huà)組件邏輯
│ ├──i18n
│ │ ├──en-US.json // 英文國(guó)際化
│ │ └──zh-CN.json // 中文國(guó)際化
│ ├──pages
│ │ └──animation
│ │ ├──animation.css // 動(dòng)畫(huà)頁(yè)面樣式
│ │ ├──animation.hml // 動(dòng)畫(huà)頁(yè)面
│ │ └──animation.js // 動(dòng)畫(huà)頁(yè)面邏輯
│ └──app.js // 程序入口
└──entry/src/main/resources // 應(yīng)用資源目錄
頁(yè)面構(gòu)建
頁(yè)面展示幾種常見(jiàn)動(dòng)畫(huà)效果:平移、旋轉(zhuǎn)、縮放以及透明度變化,界面主要由image組件和text組件組成,效果如圖所示:
< !-- animation.hml -- >
< element name='animated-cards' src="../../component/animatedCards/animatedCards.hml" >< /element >
< div class="container" >
< div class="animation-box" for="{{ value in animationList }}" >
< animated-cards icon="{{ windmillIcon }}" animation-list="{{ value }}" >< /animated-cards >
< /div >
< /div >
animation.js文件中,animationList是展示動(dòng)畫(huà)效果的列表數(shù)據(jù),windmillIcon是頁(yè)面動(dòng)畫(huà)的圖片。
// animation.js
export default {
data: {
// 動(dòng)畫(huà)列表
animationList: [
{
animationName: 'Translate',
animationStyle: 'img-translate'
},
{
animationName: 'Rotate',
animationStyle: 'img-rotate'
},
{
animationName: 'RotateY',
animationStyle: 'img-rotateY'
},
{
animationName: 'Scale',
animationStyle: 'img-scale'
},
{
animationName: 'Opacity',
animationStyle: 'img-opacity'
}
],
// 動(dòng)畫(huà)圖片
windmillIcon: '/common/images/ic_windmill.png'
}
}
動(dòng)畫(huà)實(shí)現(xiàn)
圖片的平移、旋轉(zhuǎn)、縮放以及透明度變化都是在animatedCards自定義組件中進(jìn)行實(shí)現(xiàn),界面主要由image組件和text組件組成。
< !--animatedCards.hml-- >
< div class="container" >
< div class="box" >
< text class="text" >{{ animationList.animationName }}< /text >
< div class="windmill-box" >
< image class="img {{ animationList.animationStyle }}" src="{{ icon }}" >< /image >
< /div >
< /div >
< /div >
聲明類型為Array的props,父組件可以通過(guò)設(shè)置props屬性向子組件傳遞參數(shù)。
// animatedCards.js
export default {
props: ['icon', 'animationList']
}
通過(guò)css樣式,實(shí)現(xiàn)風(fēng)車的平移、旋轉(zhuǎn)、縮放以及透明度的變化。
/* animatedCards.css */
/* 平移動(dòng)畫(huà) */
.img-translate {
animation-name: translateAnim;
}
/* 順時(shí)針旋轉(zhuǎn) */
.img-rotate {
animation-name: rotateAnim;
}
/* Y軸方向旋轉(zhuǎn) */
.img-rotateY {
animation-name: rotateYAnim;
}
/* 縮放動(dòng)畫(huà) */
.img-scale {
animation-name: scaleAnim;
}
/* 透明度變化 */
.img-opacity {
animation-name: opacityAnim;
}
/* 從-100vp平移到100vp */
@keyframes translateAnim {
from {
transform: translate(-100vp);
}
to {
transform: translate(100vp);
}
}
/* 從0°旋轉(zhuǎn)到360° */
@keyframes rotateAnim {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
/* 沿Y軸旋轉(zhuǎn),從0°旋轉(zhuǎn)到360° */
@keyframes rotateYAnim {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
/* 從0倍縮放到1.2倍大小 */
@keyframes scaleAnim {
from {
transform: scale(0);
}
to {
transform: scale(1.2);
}
}
/* 不透明度值從0變化到1 */
@keyframes opacityAnim {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
審核編輯 黃宇
-
鴻蒙
+關(guān)注
關(guān)注
60文章
2620瀏覽量
44063 -
HarmonyOS
+關(guān)注
關(guān)注
80文章
2126瀏覽量
33093 -
OpenHarmony
+關(guān)注
關(guān)注
29文章
3854瀏覽量
18629
發(fā)布評(píng)論請(qǐng)先 登錄
HarmonyOS開(kāi)發(fā)案例:【購(gòu)物車app】

HarmonyOS開(kāi)發(fā)案例:【基礎(chǔ)組件Slider的使用】

HarmonyOS開(kāi)發(fā)案例:【轉(zhuǎn)場(chǎng)動(dòng)畫(huà)】

HarmonyOS開(kāi)發(fā)案例:【動(dòng)效】

HarmonyOS開(kāi)發(fā)案例:【抽獎(jiǎng)轉(zhuǎn)盤(pán)】

HarmonyOS IoT 硬件開(kāi)發(fā)案例分享
【潤(rùn)和直播課預(yù)告@華為開(kāi)發(fā)者學(xué)院】HarmonyOS設(shè)備開(kāi)發(fā)基礎(chǔ)課程|HiSpark WiFi-IoT 智能小車套件開(kāi)發(fā)案例
直播預(yù)告丨Hello HarmonyOS進(jìn)階課程第四課——ArkUI動(dòng)畫(huà)開(kāi)發(fā)
【直播回顧】Hello HarmonyOS進(jìn)階課程第四課——ArkUI動(dòng)畫(huà)開(kāi)發(fā)
HarmonyOS屬性動(dòng)畫(huà)開(kāi)發(fā)示例(ArkTS)
許思維老師HarmonyOS IoT硬件開(kāi)發(fā)案例分享

華為開(kāi)發(fā)者分論壇HarmonyOS學(xué)生公開(kāi)課-OpenHarmony Codelabs開(kāi)發(fā)案例

HarmonyOS開(kāi)發(fā)案例:【抽獎(jiǎng)轉(zhuǎn)盤(pán)】

HarmonyOS開(kāi)發(fā)案例:【自定義下拉刷新動(dòng)畫(huà)】

評(píng)論