自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

OpenHarmony3.1中的轉(zhuǎn)場動畫

系統(tǒng) OpenHarmony
本文會學(xué)習(xí)如何設(shè)置OpenHarmony的轉(zhuǎn)場動畫,主要包括頁面的轉(zhuǎn)場動畫和組件的轉(zhuǎn)場動畫。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

本文會學(xué)習(xí)如何設(shè)置OpenHarmony的轉(zhuǎn)場動畫,主要包括頁面的轉(zhuǎn)場動畫和組件的轉(zhuǎn)場動畫。所謂轉(zhuǎn)場動畫,是指在兩個頁面之間切換或組件顯示/隱藏等操作時以動畫效果展現(xiàn)。下圖是本文案例的主界面。點擊每一個按鈕,會展示特定的轉(zhuǎn)場動畫。

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

1、底部滑入動畫

這種動畫效果可以讓A頁面切換到B頁面時,B頁面從底端往上展現(xiàn)。這是通過slide方法設(shè)置的動畫效果,代碼如下:

pageTransition() {

// 頁面入場組件:SlideEffect.Bottom 設(shè)置到入場時表示從下邊滑入,出場時表示滑出到下邊。
PageTransitionEnter({ duration: 600, curve: Curve.Smooth })
.slide(SlideEffect.Bottom)
// 頁面退場組件:SlideEffect.Bottom 設(shè)置到入場時表示從下邊滑入,出場時表示滑出到下邊。
PageTransitionExit({ duration: 600, curve: Curve.Smooth })
.slide(SlideEffect.Bottom)
}

動畫完成,會顯示下圖的頁面:

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

2、頁面自定義轉(zhuǎn)場1

下面的代碼可以通過不同的特效方法自定義轉(zhuǎn)場動畫,例如,通過opacity方法設(shè)置透明度動畫,通過scale方法設(shè)置縮放動畫。這段代碼讓頁面進場時透明度從0.2變到1,尺寸比例從0(未顯示)變到原始大?。?)。

pageTransition() {
// 頁面入場組件
PageTransitionEnter({ duration: 600, curve: Curve.Smooth })
.opacity(0.2) //入場時候透明度從0.2到1
.scale({ x: 0, y: 0 }) //入場時x、y軸縮放從0變化到1

// 頁面退場組件
PageTransitionExit({ duration: 600, curve: Curve.Smooth })
.translate({ x: 500, y: 500 }) //退場時x、y軸的偏移量為500
}

動畫完成,會顯示下圖的頁面:

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

3、頁面自定義轉(zhuǎn)場2

這也是一種自定義轉(zhuǎn)場動畫,用來控制Image組件的透明度。當入場時,Image的透明度會從0變到1(逐漸顯示),退場時Image的透明度會從1變到0(逐漸消失)。

@Entry
@Component
struct FullCustomTransition {
@State myProgress: number = 1

build() {
Stack() {
Image($rawfile('image1.jpg'))
.objectFit(ImageFit.Cover)
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
.opacity(this.myProgress)
.scale({ x: this.myProgress, y: this.myProgress })
.rotate({ x: 0, y: 0, z: 1, angle: 360 * this.myProgress })
}

pageTransition() {

// 頁面入場組件: 進場過程中會逐幀觸發(fā)onEnter回調(diào),入?yún)閯有У臍w一化進度(0% -- 100%)
PageTransitionEnter({ duration: 800, curve: Curve.Smooth })
.onEnter((type: RouteType, progress: number) => {
this.myProgress = progress // 頁面入場式myProgress從0變化到1
})

// 頁面退場組件: 進場過程中會逐幀觸發(fā)onExit回調(diào),入?yún)閯有У臍w一化進度(0% -- 100%)
PageTransitionExit({ duration: 800, curve: Curve.Smooth })
.onExit((type: RouteType, progress: number) => {
this.myProgress = 1 - progress //頁面退場式myProgress從1變化到0
})
}
}

動畫完成,會顯示下圖的頁面:

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

4、組件內(nèi)轉(zhuǎn)場

這種動畫是針對組件的,而不是針對頁面的。既然是針對組件的,就需要對組件調(diào)用transition方法。下面的代碼對組件完成了插入和刪除動畫,也就是組件添加時x、y軸縮放從0.5變化到1,透明度從0到1。 組件移除時沿y軸旋轉(zhuǎn)360度,x、y軸縮放從1變化到0。完整的實現(xiàn)代碼如下:

@Component
struct ComponentItem {
build() {
Stack({ alignContent: Alignment.Center }) {
Image($rawfile('image3.png'))
.objectFit(ImageFit.Cover)
.width('100%')
.height(120)
.borderRadius(15)
}
.height(120)
.borderRadius(15)
.width('80%')
.padding({ top: 20 })
// 組件添加時x、y軸縮放從0.5變化到1,透明度從0到1
.transition({ type: TransitionType.Insert, scale: { x: 0.5, y: 0.5 }, opacity: 0 })
// 組件移除時沿y軸旋轉(zhuǎn)360度,x、y軸縮放從1變化到0,
.transition({ type: TransitionType.Delete, rotate: { x: 0, y: 1, z: 0, angle: 360 }, scale: { x: 0, y: 0 } })
}
}
@Entry
@Component
struct ComponentTransition {
@State private isShow: boolean= false

build() {
Column() {
if (this.isShow) {
ComponentItem()
}
ComponentItem()
Button("Toggle")
.onClick(() => {
//執(zhí)行動效,動效時長600ms
animateTo({ duration: 600 }, () => {
this.isShow = !this.isShow;
})
})
.height(45)
.width(200)
.fontColor(Color.Black)
.backgroundColor('rgb(181,222,224)')
.margin({ top: 20 })
}
.padding({ left: 20, right: 20 })
.backgroundColor('#FFECECEC')
.height('100%')
.width('100%')
}
}

當點擊按鈕時,顯示按鈕的效果如下圖所示。

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

5、共享元素轉(zhuǎn)場

所有共享元素,就是指一個元素(組件)看起來屬于頁面A,又屬于頁面B,這個元素就成為共享元素。典型的應(yīng)用按鈕是共享元素一開始以小圖顯示,然后點擊,會在整個頁面顯示。下圖是小圖的效果。

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

點擊后,會整屏顯示,效果如下圖所示:

#DAYU200體驗官# OpenHarmony3.1中的轉(zhuǎn)場動畫-開源基礎(chǔ)軟件社區(qū)

這個功能由兩個ets文件完成,其中ShareItem.ets是小圖的,代碼如下,其中共享元素轉(zhuǎn)場屬性通過sharedTransition方法設(shè)置。

mport router from '@system.router'
@Entry
@Component
struct ShareItem {
build() {
Flex() {
Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
Stack() {
Image($rawfile('image2.jpg'))
// 設(shè)置共享元素轉(zhuǎn)場屬性
.sharedTransition('imageId', { duration: 600, curve: Curve.Smooth, delay: 100 })
.onClick(() => {
router.push({ uri: 'pages/SharePage' })
})
.objectFit(ImageFit.Cover)
.height('100%')
.width('100%')
.borderRadius(15)
}
.height('100%')
.width('100%')

Text('點擊查看共享元素轉(zhuǎn)場動效')
.fontSize(20)
.fontColor(Color.Black)
.fontWeight(FontWeight.Regular)
.margin({ left: 10, right: 10 })

}
.height(120)
.backgroundColor('rgb(181,222,224)')
.borderRadius(15)
.margin({ top: 20 })
}
.width('100%')
.padding({ left: 16, right: 16 })
.backgroundColor('#FFECECEC')
}
}

另外一個頁面是SharePage,用于顯示大圖,代碼如下,點擊圖像,同樣可以切換回小圖(ShareItem)。

@Entry
@Component
struct SharePage {
build() {
Stack() {
Image($rawfile('image2.jpg'))
// 設(shè)置共享元素轉(zhuǎn)場屬性
.sharedTransition('imageId', { duration: 1000, curve: Curve.Smooth, delay: 100 })
.objectFit(ImageFit.Cover)
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
}
}

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??。

責任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2022-05-07 16:13:59

DevEcoTool鴻蒙

2022-07-06 20:40:27

舒爾特方格鴻蒙

2022-06-28 14:42:26

ETS購物車應(yīng)用

2022-04-26 14:33:21

鴻蒙操作系統(tǒng)

2022-06-01 22:35:25

滑桿組件鴻蒙

2022-07-27 14:30:15

分布式數(shù)據(jù)鴻蒙

2022-04-21 11:55:06

Audio鴻蒙操作系統(tǒng)

2022-02-15 14:45:14

OpenHarmo系統(tǒng)鴻蒙

2022-03-28 15:40:34

harmony鴻蒙操作系統(tǒng)

2015-03-23 17:43:31

transitionViewControl

2022-04-11 13:57:38

HarmonyRelease操作系統(tǒng)

2021-10-12 11:07:33

動畫深度Android

2021-12-20 20:30:48

鴻蒙HarmonyOS應(yīng)用

2022-07-04 16:41:16

IPC通信HiTrace

2022-06-22 09:14:23

事件打點HiSysEvent

2022-07-08 09:55:54

CSS轉(zhuǎn)場動畫

2022-04-02 20:45:04

Hi3516開發(fā)板操作系統(tǒng)鴻蒙

2022-04-25 09:10:50

RK3568鴻蒙

2022-04-14 11:53:38

HarmonyRelease鴻蒙
點贊
收藏

51CTO技術(shù)棧公眾號