目录

Class (AnimationSet)

Modules to Import

import { map } from '@kit.MapKit';

AnimationSet

Animation set, which inherits from Animation.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

[h2]constructor

constructor(shareInterpolator: boolean)

Constructor, which is used to construct an instance of the animation set.

This API inherits from the Animation method. The interpolator is shared only when shareInterpolator is set to true. Other attributes are not shared and cannot be set.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
shareInterpolator boolean Yes

Indicates whether to share the interpolator.

- true: yes

- false: no

Example:

// Create an alpha animation: from fully transparent (0.2) to fully opaque (1)
let animation1: map.AlphaAnimation = new map.AlphaAnimation(0.2, 1);
// Create a rotation animation: from 15 degrees to 150 degrees
let animation2: map.RotateAnimation = new map.RotateAnimation(15, 150);
// Create a scale animation: from the original size (1) to 3x scale
let animation3: map.ScaleAnimation = new map.ScaleAnimation(1, 3, 1, 3);
// Create an animation set. The value true indicates that only one animation is played at a time.
let animation: map.AnimationSet = new map.AnimationSet(true);
// Set the animation interpolator to linear (constant speed).
animation.setInterpolator(Curve.Linear);
// Add the preceding three animations to the animation set.
animation.addAnimation(animation1);
animation.addAnimation(animation2);
animation.addAnimation(animation3);
// Clear the animation set.
animation.clearAnimation();

[h2]addAnimation

addAnimation(animation: Animation): void

Adds an animation.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
animation Animation Yes Animation object to be added.

Example:

// Create an alpha animation: gradient from fully transparent (0.2) to fully opaque (1)
let animation1: map.AlphaAnimation = new map.AlphaAnimation(0.2, 1);
// Create a rotation animation: from 15 degrees to 150 degrees
let animation2: map.RotateAnimation = new map.RotateAnimation(15, 150);
// Create a scale animation: from original size (1,1) to (3,3)
let animation3: map.ScaleAnimation = new map.ScaleAnimation(1, 3, 1, 3);
// Create an animation set. The value true indicates that only one animation is played at a time (canceling the ongoing animation to play the next).
let animation: map.AnimationSet = new map.AnimationSet(true);
// Add the alpha animation to the animation set.
animation.addAnimation(animation1);
// Add the rotation animation to the animation set.
animation.addAnimation(animation2);
// Add the scale animation to the animation set.
animation.addAnimation(animation3);

[h2]clearAnimation

clearAnimation(): void

Deletes animations.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Example:

// Create an alpha animation: gradient from fully transparent (0.2) to fully opaque (1)
let animation1: map.AlphaAnimation = new map.AlphaAnimation(0.2, 1);
// Create a rotation animation: from 15 degrees to 150 degrees
let animation2: map.RotateAnimation = new map.RotateAnimation(15, 150);
// Create a scale animation: from original size (1,1) to (3,3)
let animation3: map.ScaleAnimation = new map.ScaleAnimation(1, 3, 1, 3);
// Create an animation set. The value true indicates that only one animation is played at a time (canceling the ongoing animation to play the next).
let animation: map.AnimationSet = new map.AnimationSet(true);
// Add the alpha animation to the animation set.
animation.addAnimation(animation1);
// Add the rotation animation to the animation set.
animation.addAnimation(animation2);
// Add the scale animation to the animation set.
animation.addAnimation(animation3);
// Clear the animation set.
animation.clearAnimation();