设置组件进行位移动画时的运动路径。
说明 : 从API Version 7开始支持。开发语言ets.
属性 :
名称 |
参数类型 |
默认值 |
描述 |
motionPath |
{<br/>path: string,<br/>from?: number,<br/>to?: number,<br/>rotatable?: boolean<br/>}<br/>说明:<br/>path中支持使用start和end进行起点和终点的替代,如:<br/>'Mstart.x start.y L50 50 Lend.x end.y Z' |
{<br/>'',<br/>0.0,<br/>1.0,<br/>false<br/>} |
设置组件的运动路径,入参说明如下:<br/>- path:位移动画的运动路径,使用svg路径字符串。<br/>- from:运动路径的起点,默认为0.0。<br/>- to:运动路径的终点,默认为1.0。<br/>- rotatable:是否跟随路径进行旋转。 |
示例代码:
@Entry
@Component
struct PathAnimation {
@State toggle: boolean = true
build() {
Column() {
Button('click me')
// 执行动画:从起点移动到(300,200),再到(300,500),再到终点
.motionPath({ path: 'Mstart.x start.y L400 300 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('50%').borderWidth(2)
.alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.End)
.justifyContent(this.toggle ? FlexAlign.Start : FlexAlign.End)
}
}
示例效果:



代码地址:https://e.gitee.com/jltfcloudcn/repos/jltfcloudcn/jump_to/tree/master/AnimationMuster