W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
設(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)。 |
- // xxx.ets
- @Entry
- @Component
- struct MotionPathExample {
- @State toggle: boolean = true
- build() {
- Column() {
- Button('click me').margin(50)
- // 執(zhí)行動(dòng)畫:從起點(diǎn)移動(dòng)到(300,200),再到(300,500),再到終點(diǎn)
- .motionPath({ path: 'Mstart.x start.y L300 200 L300 500 Lend.x end.y', from: 0.0, to: 1.0, rotatable: true })
- .onClick(() => {
- animateTo({ duration: 4000, curve: Curve.Linear }, () => {
- this.toggle = !this.toggle // 通過this.toggle變化組件的位置
- })
- })
- }.width('100%').height('100%').alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.Center)
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: