全屏模態(tài)轉(zhuǎn)場
通過bindContentCover屬性為組件綁定全屏模態(tài)頁面,在組件插入和刪除時可通過設(shè)置轉(zhuǎn)場參數(shù)ModalTransition顯示過渡動效。
說明:
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
從API Version 10開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。 不支持橫豎屏切換。
屬性
| 名稱 | 參數(shù) | 參數(shù)描述 |
|---|---|---|
| bindContentCover | isShow: boolean, builder: [CustomBuilder], options?: [ContentCoverOptions] | 給組件綁定全屏模態(tài)頁面,點擊后顯示模態(tài)頁面。模態(tài)頁面內(nèi)容自定義,顯示方式可設(shè)置無動畫過渡,上下切換過渡以及透明漸變過渡方式。 isShow: 是否顯示全屏模態(tài)頁面。 從API version 10開始,該參數(shù)支持[$$]雙向綁定變量 builder: 配置全屏模態(tài)頁面內(nèi)容。 options: 配置全屏模態(tài)頁面的可選屬性。 |
ContentCoverOptions
| 名稱 | 類型 | 必填 | 描述 |
|---|---|---|---|
| modalTransition | [ModalTransition] | 否 | 全屏模態(tài)頁面的轉(zhuǎn)場方式。 |
| backgroundColor | [ResourceColor] | 否 | 全屏模態(tài)頁面的背板顏色。 |
| onAppear | () => void | 否 | 全屏模態(tài)頁面顯示回調(diào)函數(shù)。 |
| onDisappear | () => void | 否 | 全屏模態(tài)頁面回退回調(diào)函數(shù)。 |
示例
示例1
全屏模態(tài)無動畫轉(zhuǎn)場模式下,自定義轉(zhuǎn)場動畫。
// xxx.ets
@Entry
@Component
struct ModalTransitionExample {
@State isShow:boolean = false
@State isShow2:boolean = false
@Builder myBuilder2() {
Column() {
Button("close modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = false;
})
}
.width('100%')
.height('100%')
}
@Builder myBuilder() {
Column() {
Button("transition modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = true;
}).bindContentCover($$this.isShow2, this.myBuilder2(), {modalTransition: ModalTransition.NONE, backgroundColor: Color.Orange, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
Button("close modal 1")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow = false;
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
build() {
Column() {
Button("transition modal 1")
.onClick(() = > {
this.isShow = true
})
.fontSize(20)
.margin(10)
.bindContentCover($$this.isShow, this.myBuilder(), {modalTransition: ModalTransition.NONE, backgroundColor: Color.Pink, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
}
.justifyContent(FlexAlign.Center)
.backgroundColor("#ff49c8ab")
.width('100%')
.height('100%')
}
}

示例2
全屏模態(tài)無動畫轉(zhuǎn)場模式下,自定義轉(zhuǎn)場動畫。
// xxx.ets
import curves from '@ohos.curves';
@Entry
@Component
struct ModalTransitionExample {
@State @Watch("isShow1Change") isShow:boolean = false
@State @Watch("isShow2Change") isShow2:boolean = false
@State isScale1:number = 1;
@State isScale2:number = 1;
@State flag: boolean = true
@State show: string = 'show'
isShow1Change() {
this.isShow ? this.isScale1 = 0.95 : this.isScale1 = 1
}
isShow2Change() {
this.isShow2 ? this.isScale2 = 0.95 : this.isScale2 = 1
}
@Builder myBuilder2() {
Column() {
Button("close modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = false;
})
}
.width('100%')
.height('100%')
}
@Builder myBuilder() {
Column() {
Button("transition modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = true;
}).bindContentCover($$this.isShow2, this.myBuilder2(), {modalTransition: ModalTransition.NONE, backgroundColor: Color.Orange, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
Button("close modal 1")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow = false;
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.scale({x: this.isScale2, y: this.isScale2})
.animation({curve:curves.springMotion()})
}
build() {
Column() {
Button("transition modal 1")
.onClick(() = > {
this.isShow = true
})
.fontSize(20)
.margin(10)
.bindContentCover($$this.isShow, this.myBuilder(), {modalTransition: ModalTransition.NONE, backgroundColor: Color.Pink, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
}
.justifyContent(FlexAlign.Center)
.backgroundColor("#ff49c8ab")
.width('100%')
.height('100%')
.scale({ x: this.isScale1, y: this.isScale1 })
.animation({ curve: curves.springMotion() })
}
}

示例3
全屏模態(tài)上下切換轉(zhuǎn)場。
// xxx.ets
@Entry
@Component
struct ModalTransitionExample {
@State isShow:boolean = false
@State isShow2:boolean = false
@Builder myBuilder2() {
Column() {
Button("close modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = false;
})
}
.width('100%')
.height('100%')
}
@Builder myBuilder() {
Column() {
Button("transition modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = true;
}).bindContentCover(this.isShow2, this.myBuilder2(), {modalTransition: ModalTransition.DEFAULT, backgroundColor: Color.Gray, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
Button("close modal 1")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow = false;
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
build() {
Column() {
Button("transition modal 1")
.onClick(() = > {
this.isShow = true
})
.fontSize(20)
.margin(10)
.bindContentCover($$this.isShow, this.myBuilder(), {modalTransition: ModalTransition.DEFAULT, backgroundColor: Color.Pink, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
}
.justifyContent(FlexAlign.Center)
.backgroundColor(Color.White)
.width('100%')
.height('100%')
}
}

示例4
全屏模態(tài)透明度漸變轉(zhuǎn)場。
`HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿`
// xxx.ets
@Entry
@Component
struct ModalTransitionExample {
@State isShow:boolean = false
@State isShow2:boolean = false
@Builder myBuilder2() {
Column() {
Button("close modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = false;
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
@Builder myBuilder() {
Column() {
Button("transition modal 2")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow2 = true;
}).bindContentCover(this.isShow2, this.myBuilder2(), {modalTransition: ModalTransition.ALPHA, backgroundColor: Color.Gray, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
Button("close modal 1")
.margin(10)
.fontSize(20)
.onClick(()= >{
this.isShow = false;
})
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
build() {
Column() {
Button("transition modal 1")
.onClick(() = > {
this.isShow = true
})
.fontSize(20)
.margin(10)
.bindContentCover($$this.isShow, this.myBuilder(), {modalTransition: ModalTransition.ALPHA, backgroundColor: Color.Pink, onAppear: () = > {console.log("BindContentCover onAppear.")}, onDisappear: () = > {console.log("BindContentCover onDisappear.")}})
}
.justifyContent(FlexAlign.Center)
.backgroundColor(Color.White)
.width('100%')
.height('100%')
}
}

審核編輯 黃宇
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
模態(tài)
+關(guān)注
關(guān)注
0文章
9瀏覽量
6433 -
鴻蒙
+關(guān)注
關(guān)注
60文章
3031瀏覽量
46194
發(fā)布評論請先 登錄
相關(guān)推薦
熱點推薦
HarmonyOS開發(fā)案例:【轉(zhuǎn)場動畫】
在本教程中,我們將會通過一個簡單的樣例,學(xué)習(xí)如何基于ArkTS的聲明式開發(fā)范式開發(fā)轉(zhuǎn)場動畫。其中
OpenHarmony實戰(zhàn)開發(fā)-如何實現(xiàn)模態(tài)轉(zhuǎn)場
實現(xiàn)。
使用bindContentCover構(gòu)建全屏模態(tài)轉(zhuǎn)場效果
bindContentCover接口用于為組件綁定全屏模態(tài)頁面,在組件出現(xiàn)
發(fā)表于 04-28 14:47
模態(tài)窗口的設(shè)置問題
Labview中,一個窗口如果設(shè)置為模態(tài)窗口,則打開后,點擊其他窗口應(yīng)該是沒有作用的。我設(shè)置的幾個子VI為模態(tài)窗口,效果都沒有問題。但有一個子VI,
發(fā)表于 11-28 21:56
【木棉花】ArkUI轉(zhuǎn)場動畫的使用——學(xué)習(xí)筆記
建名為Item的子組件,聲明子組件Item的UI布局并添加樣式。創(chuàng)建Stack組件,包含圖片和文本,然后添加文本信息和頁面跳轉(zhuǎn)事件,定義變量text和uri。其中text用于給Text組件設(shè)置文本信息
發(fā)表于 12-19 18:00
Harmony/OpenHarmony應(yīng)用開發(fā)-轉(zhuǎn)場動畫組件內(nèi)轉(zhuǎn)場
跟隨animateTo中的配置)。說明: 從API Version 7開始支持。開發(fā)語言ets.屬性:名稱參數(shù)類型參數(shù)描述transitionTransitionOptions所有參數(shù)均為可選參數(shù)
發(fā)表于 12-28 16:19
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-轉(zhuǎn)場動畫共享元素轉(zhuǎn)場
設(shè)置頁面間轉(zhuǎn)場時共享元素的轉(zhuǎn)場動效。說明: 從API Version 7開始支持。開發(fā)語言ets.示例代碼
發(fā)表于 01-04 17:22
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS的聲明式開發(fā)范式
基于ArkTS的聲明式開發(fā)范式的方舟開發(fā)框架是一套開發(fā)極簡、高性能、
發(fā)表于 01-17 15:09
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【按鍵事件】
按鍵事件指組件與鍵盤、遙控器等按鍵設(shè)備交互時觸發(fā)的事件,適用于所有可獲焦組件,例如Button。對于Text,Image等默認(rèn)不可獲焦的組件,可以設(shè)置focusable屬性為true后使用按鍵事件。
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【顯隱控制】 通用屬性
控制當(dāng)前組件顯示或隱藏。注意,即使組件處于隱藏狀態(tài),在頁面刷新時仍存在重新創(chuàng)建過程,因此當(dāng)對性能有嚴(yán)格要求時建議使用[條件渲染]代替。 默認(rèn)值:Visibility.Visible 從API version 9開始,該接口支持在ArkTS卡片中使用。
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【形狀裁剪】 通用屬性
參數(shù)為相應(yīng)類型的組件,按指定的形狀對當(dāng)前組件進行裁剪;參數(shù)為boolean類型時,設(shè)置是否按照父容器邊緣輪廓進行裁剪。 默認(rèn)值:false 從API version 9開始,該接口支持在ArkTS卡片中使用。
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【半模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場設(shè)置
通過bindSheet屬性為組件綁定半模態(tài)頁面,在組件插入時可通過設(shè)置自定義或默認(rèn)的內(nèi)置高度確定半模態(tài)大小。
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【全屏模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場設(shè)置
評論