ts-motion-path-animation.md 1.7 KB
Newer Older
Z
zengyawen 已提交
1 2 3
# Motion Path Animation


E
ester.zhou 已提交
4 5
> **NOTE**
>
Z
zengyawen 已提交
6
> This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
7

Z
zengyawen 已提交
8

E
ester.zhou 已提交
9
The attributes below can be used to set the motion path of the component in a translation animation.
Z
zengyawen 已提交
10 11


Z
zengyawen 已提交
12 13
## Attributes

E
ester.zhou 已提交
14
| Name | Type | Default Value | Description |
Z
zengyawen 已提交
15
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
16
| motionPath | {<br/>path: string,<br/>from?: number,<br/>to?: number,<br/>rotatable?: boolean<br/>}<br/>**NOTE**<br/>In a path, **start** and **end** can be used to replace the start point and end point. Example:<br/>'Mstart.x start.y L50 50 Lend.x end.y Z' | {<br/>"",<br/>0.0,<br/>1.0,<br/>false<br/>} | Motion path of the component. The input parameters are described as follows:<br/>- **path**: motion path of the translation animation. The **svg** path string is used.<br/>- **from**: start point of the motion path. The default value is **0.0**.<br/>- **to**: end point of the motion path. The default value is **1.0**.<br/>- **rotatable**: whether to rotate along the path. |
Z
zengyawen 已提交
17 18


Z
zengyawen 已提交
19 20
## Example

E
ester.zhou 已提交
21

Z
zengyawen 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
```
@Entry
@Component
struct MotionPathExample {
  @State offsetX: number = 0
  @State offsetY: number = 0
  @State toggle: boolean = true

  build() {
    Column() {
      Button('click me')
        .motionPath({ path: 'Mstart.x start.y L300 200 L300 500 Lend.x end.y', from: 0.0, to: 1.0, rotatable: true })
        .onClick((event: ClickEvent) => {
          animateTo({ duration: 4000, curve: Curve.Linear }, () => {
            this.toggle = !this.toggle;
          })
        }).backgroundColor(0x317aff)
    }.width('100%').height('100%').alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.Center)
  }
}
```

Z
zengyawen 已提交
44
![en-us_image_0000001212378420](figures/en-us_image_0000001212378420.gif)