• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Motion Blur
2
3You can apply a motion blur effect to a component being scaled or moved. This effect must be used together with the **onFinish** parameter of **AnimateParam**.
4
5>  **NOTE**
6>
7>  The initial APIs of this module are supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
8
9## motionBlur
10
11motionBlur(value: MotionBlurOptions)
12
13Apply a motion blur effect to the component being scaled or moved.
14
151. Do not use this API in intra-component transitions, shared element transitions, implicit element transitions, or particle animations. Doing so may cause unexpected results.
16
172. The **radius** parameter of **motionBlur** must be set to **0** for the initial state. Otherwise, there may be unexpected results during a cold start.
18
193. This API must be used together with the **onFinish** parameter of **AnimateParam**. Its **radius** parameter must be set to **0** when the animation ends; otherwise, there may be unexpected results.
20
214. When using this API, do not frequently change the blur radius of the same component; otherwise, there may be unexpected results. For example, if you frequently click the image in the example, the blur effect may not work sometimes.
22
235. To avoid unexpected results, make sure the coordinates of the motion blur anchor point are the same as those of the animation scaling anchor point.
24
256. To avoid unexpected results, set the blur radius to a value less than 1.
26
27**Atomic service API**: This API can be used in atomic services since API version 12.
28
29**Parameters**
30
31| Name| Type                                           | Mandatory| Description              |
32| ------ | ----------------------------------------------- | ---- | ------------------ |
33| value  | [MotionBlurOptions](#motionbluroptions) | Yes  | Motion blur options.|
34
35## motionBlur<sup>18+</sup>
36
37motionBlur(motionBlur: Optional\<MotionBlurOptions>)
38
39Apply a motion blur effect to the component being scaled or moved. Compared to [motionBlur](#motionblur), this API supports the **undefined** type for the **motionBlur** parameter.
40
411. Do not use this API in intra-component transitions, shared element transitions, implicit element transitions, or particle animations. Doing so may cause unexpected results.
42
432. The **radius** parameter of **motionBlur** must be set to **0** for the initial state. Otherwise, there may be unexpected results during a cold start.
44
453. This API must be used together with the **onFinish** parameter of **AnimateParam**. Its **radius** parameter must be set to **0** when the animation ends; otherwise, there may be unexpected results.
46
474. When using this API, do not frequently change the blur radius of the same component; otherwise, there may be unexpected results. For example, if you frequently click the image in the example, the blur effect may not work sometimes.
48
495. To avoid unexpected results, make sure the coordinates of the motion blur anchor point are the same as those of the animation scaling anchor point.
50
516. To avoid unexpected results, set the blur radius to a value less than 1.
52
53**Atomic service API**: This API can be used in atomic services since API version 18.
54
55**Parameters**
56
57|   Name   |    Type                                                     |  Mandatory |     Description                                                      |
58| ---------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
59| motionBlur | Optional\<[MotionBlurOptions](#motionbluroptions)> | Yes  | Motion blur options.<br>If **motionBlur** is set to **undefined**, the previous value is retained.|
60
61## MotionBlurOptions
62
63**Atomic service API**: This API can be used in atomic services since API version 12.
64
65| Name         | Type                                                       | Mandatory | Description                                                        |
66| ------------- | ----------------------------------------------------------- | ----- | ------------------------------------------------------------ |
67| radius | number      | Yes   | Blur radius. The value range is [0.0, ∞). You are advised to set it to a value less than 1.0.|
68| anchor | [MotionBlurAnchor](#motionbluranchor) | Yes   | Coordinates of the motion blur anchor point. They must be the same as those of the animation scaling anchor point.|
69
70## MotionBlurAnchor
71
72**Atomic service API**: This API can be used in atomic services since API version 12.
73
74| Name         | Type                                                       | Mandatory | Description                                                        |
75| ------------- | ----------------------------------------------------------- | ----- | ------------------------------------------------------------ |
76| x | number      | Yes   | X-coordinate of the anchor point. The value range is [0.0, 1.0].|
77| y | number      | Yes   | Y-coordinate of the anchor point. The value range is [0.0, 1.0].|
78
79## Example
80
81This example demonstrates how to apply a motion blur effect.
82```ts
83// xxx.ets
84import { curves } from '@kit.ArkUI';
85
86@Entry
87@Component
88struct motionBlurTest {
89  @State widthSize: number = 400
90  @State heightSize: number = 320
91  @State flag: boolean = true
92  @State radius: number = 0
93  @State x: number = 0
94  @State y: number = 0
95
96  build() {
97    Column() {
98      Column() {
99        Image($r('app.media.testImg'))
100          .width(this.widthSize)
101          .height(this.heightSize)
102          .onClick(() => {
103            this.radius = 5;
104            this.x = 0.5;
105            this.y = 0.5;
106            if (this.flag) {
107              this.widthSize = 100;
108              this.heightSize = 80;
109            } else {
110              this.widthSize = 400;
111              this.heightSize = 320;
112            }
113            this.flag = !this.flag;
114          })
115          .animation({
116            duration: 2000,
117            curve: curves.springCurve(10, 1, 228, 30),
118            onFinish: () => {
119              this.radius = 0;
120            }
121          })
122          .motionBlur({ radius: this.radius, anchor: { x: this.x, y: this.y } })
123      }
124    }.width('100%').margin({ top: 5 })
125  }
126}
127```
128
129![motionBlurTest](figures/motionBlur.gif)
130