以lottie示例使用三方库
@ohos/lottie是基于lottie-web开发,集成在三方库社区内的开源版本,是HarmonyOS系统中复杂动画的一种解决方案。
ohpm install @ohos/lottie
ohpm uninstall @ohos/lottie
安装完成后在根目录下的oh-package.json5中,可以找到lottie

import lottie from '@ohos/lottie'
// 初始化渲染上下文
private renderingSettings: RenderingContextSettings = new RenderingContextSettings(true);
private renderingContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.renderingSettings);
准备JSON文件
关联画布
// 加载Canvas画布
Canvas(this.renderingContext)
this.animateItem = lottie.loadAnimation({
container: this.renderingContext,
renderer: 'canvas',
loop: 10,
autoplay: true,
name: this.animateName,
path: 'common/lottie/data.json'
});
lottie.play();
MacOS实用ohpm命令时报错 zsh: command not found: ohpm 的解决方法:
/Users/xxx/Library/Huawei/ohpm
vim .bash_profile
将ohpm环境变量配置到文件中:
# HUAWEI
export OHPM_HOME=/Users/xxx/Library/Huawei/ohpm
export PATH=${PATH}:${OHPM_HOME}/bin
# HUAWEI END
并输入命令 source .bash_profile 使配置生效:
source .bash_profile
vim .zshrc
sourch ~/.zshrc