动画抽象类。Animation类用于控制地图元素的动画效果,支持旋转、缩放、平移等多种动画类型,适用于地图交互增强、路径动画展示等场景。
动画持续时间默认值为250ms;
动画执行完成后的状态,默认值为AnimationFillMode.FORWARDS;
动画插值器,默认值为Curve.Linear;
动画重复执行的次数,默认值为0;
重复执行的模式,默认值为AnimationRepeatMode.RESTART。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
示例:
let animation = new map.RotateAnimation(0, 270);
// 动画执行时间
animation.setDuration(2000);
// 动画结束状态
animation.setFillMode(map.AnimationFillMode.BACKWARDS);
// 动画重复模式
animation.setRepeatMode(map.AnimationRepeatMode.REVERSE);
// 动画重复次数
animation.setRepeatCount(100);
// 根据开发需要设置动画监听
let callbackStart = () => {
console.info("animationStart", `callback`);
};
let callbackEnd = () => {
console.info("animationEnd", `callback`);
};
animation.on("animationStart", callbackStart);
animation.on("animationEnd", callbackEnd); setDuration(duration: number): void
设置动画持续时间。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| duration | number | 是 | 动画持续时间,单位:ms,取值范围:大于等于0,异常值不处理。 |
示例:
animation.setDuration(3000);
setFillMode(fillMode: AnimationFillMode): void
设置动画执行完成后的状态。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| fillMode | AnimationFillMode | 是 | 动画执行完成后的状态。 |
示例:
animation.setFillMode(map.AnimationFillMode.BACKWARDS);
setInterpolator(curve: Curves.Curve): void
设置动画插值器。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| curve | Curves.Curve | 是 | 动画插值器。 |
示例:
animation.setInterpolator(Curve.Linear);
setRepeatCount(repeatCount: number): void
设置动画重复执行的次数。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| repeatCount | number | 是 | 动画重复执行的次数。 正数:根据值重复执行 0:动画不重复执行 -1:执行次数是无限 小于-1或其他异常值,取值默认为0 |
示例:
animation.setRepeatCount(100);
setRepeatMode(repeatMode: AnimationRepeatMode): void
设置重复执行的模式,默认从前往后执行。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| repeatMode | AnimationRepeatMode | 是 | 重复执行的模式。 |
示例:
animation.setRepeatMode(map.AnimationRepeatMode.RESTART);
on(type: 'start', callback: Callback<void>): void
监听动画开始事件。使用callback异步回调。
建议使用animation.on(type: 'animationStart')。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'start':动画开始事件。 |
| callback | Callback<void> | 是 | 回调函数,无返回结果。 |
示例:
animation.on("start", () => {
console.info(`start alphaAnimation`);
}); off(type: 'start', callback: Callback<void>): void
取消监听动画开始事件。使用callback异步回调。
建议使用animation.off(type: 'animationStart')。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'start':动画开始事件。 |
| callback | Callback<void> | 是 | 回调函数,无返回结果。 |
示例:
animation.off("start", () => {
console.info(`start alphaAnimation`);
}); on(type: 'end', callback: Callback<void>): void
监听动画结束事件。使用callback异步回调。
建议使用animation.on(type: 'animationEnd')。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'end':动画结束事件。 |
| callback | Callback<void> | 是 | 回调函数,无返回结果。 |
示例:
animation.on("end", () => {
console.info(`end alphaAnimation`);
}); off(type: 'end', callback: Callback<void>): void
取消监听动画结束事件。使用callback异步回调。
建议使用animation.off(type: 'animationEnd')。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 4.1.0(11)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'end':动画结束事件。 |
| callback | Callback<void> | 是 | 回调函数,无返回结果。 |
示例:
animation.off("end", () => {
console.info(`end alphaAnimation`);
}); on(type: 'animationStart', callback: Callback<void>): void
监听动画开始事件。支持传递多个callback异步回调。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'animationStart':监听动画开始事件。 |
| callback | Callback<void> | 是 | 回调函数,无返回结果。监听动画开始事件。 |
示例:
let callback1 = () => {
console.info("animationStart", `callback1`);
};
let callback2 = () => {
console.info("animationStart", `callback2`);
};
let callback3 = () => {
console.info("animationStart", `callback3`);
};
animation.on("animationStart", callback1);
animation.on("animationStart", callback2);
animation.on("animationStart", callback3); off(type: 'animationStart', callback?: Callback<void>): void
取消监听动画开始事件。支持传递多个callback异步回调。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'animationStart':监听动画开始事件。 |
| callback | Callback<void> | 否 | 回调函数,无返回结果。取消监听动画开始事件。 - callback为空:取消所有callback回调。 - callback非空:取消指定的callback回调。 |
示例:
let callback1 = () => {
console.info("animationStart", `callback1`);
};
let callback2 = () => {
console.info("animationStart", `callback2`);
};
let callback3 = () => {
console.info("animationStart", `callback3`);
};
animation.on("animationStart", callback1);
animation.on("animationStart", callback2);
animation.on("animationStart", callback3);
// 只取消callback1对象的事件响应,当animationStart事件发生时,callback2和callback3会正常被调用
animation.off('animationStart', callback1);
// 取消全部animationStart事件响应
animation.off('animationStart'); on(type: 'animationEnd', callback: Callback<void>): void
监听动画结束事件。支持传递多个callback异步回调。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'animationEnd':动画结束事件。 |
| callback | Callback<void> | 是 | 回调函数,无返回结果。监听动画结束事件。 |
示例:
let callback1 = () => {
console.info("animationEnd", `callback1`);
};
let callback2 = () => {
console.info("animationEnd", `callback2`);
};
let callback3 = () => {
console.info("animationEnd", `callback3`);
};
animation.on("animationEnd", callback1);
animation.on("animationEnd", callback2);
animation.on("animationEnd", callback3); off(type: 'animationEnd', callback?: Callback<void>): void
取消监听动画结束事件。支持传递多个callback异步回调。
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Map.Core
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 'animationEnd':监听动画结束事件。 |
| callback | Callback<void> | 否 | 回调函数,无返回结果。取消监听动画结束事件。 - callback为空:取消所有callback回调。 - callback非空:取消指定的callback回调。 |
示例:
let callback1 = () => {
console.info("animationEnd", `callback1`);
};
let callback2 = () => {
console.info("animationEnd", `callback2`);
};
let callback3 = () => {
console.info("animationEnd", `callback3`);
};
animation.on("animationEnd", callback1);
animation.on("animationEnd", callback2);
animation.on("animationEnd", callback3);
// 只取消callback1对象的事件响应,当animationEnd事件发生时,callback2和callback3会正常被调用
animation.off('animationEnd', callback1);
// 取消全部animationEnd事件响应
animation.off('animationEnd');