路徑動(dòng)畫

2024-01-22 18:19 更新

設(shè)置組件進(jìn)行位移動(dòng)畫時(shí)的運(yùn)動(dòng)路徑。

說明

從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

屬性

名稱

參數(shù)

描述

motionPath

{

path: string,

from?: number,

to?: number,

rotatable?: boolean

}

設(shè)置組件的運(yùn)動(dòng)路徑。

- path:位移動(dòng)畫的運(yùn)動(dòng)路徑,使用svg路徑字符串。path中支持使用start和end進(jìn)行起點(diǎn)和終點(diǎn)的替代,如:'Mstart.x start.y L50 50 Lend.x end.y Z',更多說明請參考繪制路徑。

- from:運(yùn)動(dòng)路徑的起點(diǎn)。

取值范圍:[0, 1]

- to:運(yùn)動(dòng)路徑的終點(diǎn)。

取值范圍:[0, 1]

- rotatable:是否跟隨路徑進(jìn)行旋轉(zhuǎn)。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct MotionPathExample {
  5. @State toggle: boolean = true
  6. build() {
  7. Column() {
  8. Button('click me').margin(50)
  9. // 執(zhí)行動(dòng)畫:從起點(diǎn)移動(dòng)到(300,200),再到(300,500),再到終點(diǎn)
  10. .motionPath({ path: 'Mstart.x start.y L300 200 L300 500 Lend.x end.y', from: 0.0, to: 1.0, rotatable: true })
  11. .onClick(() => {
  12. animateTo({ duration: 4000, curve: Curve.Linear }, () => {
  13. this.toggle = !this.toggle // 通過this.toggle變化組件的位置
  14. })
  15. })
  16. }.width('100%').height('100%').alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.Center)
  17. }
  18. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號