0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【全屏模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場設(shè)置

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-06-12 15:47 ? 次閱讀

全屏模態(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ù)描述
bindContentCoverisShow: 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%')
  }
}

zh-cn_full_screen_modal_none_1

示例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() })
  }
}

zh-cn_full_screen_modal_none_2

示例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%')
  }
}

zh-cn_full_screen_modal_default

示例4

全屏模態(tài)透明度漸變轉(zhuǎn)場。
鴻蒙文檔.png

`HarmonyOSOpenHarmony鴻蒙文檔籽料: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%')
  }
}

zh-cn_full_screen_modal_alpha

審核編輯 黃宇

聲明:本文內(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

    文章

    8

    瀏覽量

    6251
  • 鴻蒙
    +關(guān)注

    關(guān)注

    57

    文章

    2291

    瀏覽量

    42631
收藏 人收藏

    評論

    相關(guān)推薦

    HarmonyOS開發(fā)案例:【轉(zhuǎn)場動畫】

    在本教程中,我們將會通過一個簡單的樣例,學(xué)習(xí)如何基于ArkTS聲明開發(fā)范式開發(fā)轉(zhuǎn)場動畫。其中
    的頭像 發(fā)表于 05-06 15:42 ?924次閱讀
    HarmonyOS<b class='flag-5'>開發(fā)</b>案例:【<b class='flag-5'>轉(zhuǎn)場</b>動畫】

    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

    HarmonyOS應(yīng)用開發(fā)-ACE 2.0轉(zhuǎn)場動畫體驗

    一、組件說明展現(xiàn)了ACE 2.0轉(zhuǎn)場動畫的使用。其中包含頁面間轉(zhuǎn)場、組件內(nèi)轉(zhuǎn)場以及共享元素轉(zhuǎn)場。二、效果圖三、完整代碼地址https://gitee.com/jltfcloudcn/j
    發(fā)表于 08-23 10:30

    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后使用按鍵事件。
    的頭像 發(fā)表于 05-28 18:12 ?751次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【按鍵事件】

    鴻蒙ArkTS聲明開發(fā)平臺支持列表【顯隱控制】 通用屬性

    控制當(dāng)前組件顯示或隱藏。注意,即使組件處于隱藏狀態(tài),在頁面刷新時仍存在重新創(chuàng)建過程,因此當(dāng)對性能有嚴(yán)格要求時建議使用[條件渲染]代替。 默認(rèn)值:Visibility.Visible 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發(fā)表于 06-03 14:46 ?498次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【顯隱控制】 通用屬性

    鴻蒙ArkTS聲明開發(fā)平臺支持列表【形狀裁剪】 通用屬性

    參數(shù)為相應(yīng)類型的組件,按指定的形狀對當(dāng)前組件進(jìn)行裁剪;參數(shù)為boolean類型時,設(shè)置是否按照父容器邊緣輪廓進(jìn)行裁剪。 默認(rèn)值:false 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發(fā)表于 06-04 15:22 ?361次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【形狀裁剪】 通用屬性

    鴻蒙ArkTS聲明開發(fā)平臺支持列表【菜單控制】 通用屬性

    為組件綁定彈出菜單,彈出菜單以垂直列表形式顯示菜單項,可通過長按、點擊或鼠標(biāo)右鍵觸發(fā)。
    的頭像 發(fā)表于 06-06 09:17 ?448次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【菜單控制】 通用屬性

    鴻蒙ArkTS聲明開發(fā)平臺支持列表【多態(tài)樣式】 通用屬性

    設(shè)置組件不同狀態(tài)的樣式。 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發(fā)表于 06-07 09:48 ?316次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【多態(tài)樣式】 通用屬性

    鴻蒙ArkTS聲明開發(fā)平臺支持列表【前景色設(shè)置】 通用屬性

    設(shè)置組件的前景顏色或者根據(jù)智能取色策略設(shè)置前景顏色。
    的頭像 發(fā)表于 06-07 16:19 ?332次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【前景色<b class='flag-5'>設(shè)置</b>】 通用屬性

    鴻蒙ArkTS聲明開發(fā)平臺支持列表【半模態(tài)轉(zhuǎn)場模態(tài)轉(zhuǎn)場設(shè)置

    通過bindSheet屬性為組件綁定半模態(tài)頁面,在組件插入時可通過設(shè)置自定義或默認(rèn)的內(nèi)置高度確定半模態(tài)大小。
    的頭像 發(fā)表于 06-12 21:09 ?761次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【半<b class='flag-5'>模態(tài)</b><b class='flag-5'>轉(zhuǎn)場</b>】<b class='flag-5'>模態(tài)</b><b class='flag-5'>轉(zhuǎn)場</b><b class='flag-5'>設(shè)置</b>