以下是一个使用 Objective-C 代码加载三个 Lottie JSON 动画的示例:

首先,确保已将 Lottie 库添加到您的项目中,并导入 Lottie 头文件:

#import <Lottie/Lottie.h>

然后,创建一个 LottieAnimationView 实例,并从三个 JSON 文件中加载动画:

LottieAnimationView *animationView1 = [[LottieAnimationView alloc] init];
animationView1.frame = CGRectMake(0, 0, 200, 200);
animationView1.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
animationView1.animation = [LOTAnimationView animationNamed:'animation1.json'];
animationView1.loopAnimation = YES;
[animationView1 play];

LottieAnimationView *animationView2 = [[LottieAnimationView alloc] init];
animationView2.frame = CGRectMake(0, 0, 200, 200);
animationView2.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 - 250);
animationView2.animation = [LOTAnimationView animationNamed:'animation2.json'];
animationView2.loopAnimation = YES;
[animationView2 play];

LottieAnimationView *animationView3 = [[LottieAnimationView alloc] init];
animationView3.frame = CGRectMake(0, 0, 200, 200);
animationView3.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 + 250);
animationView3.animation = [LOTAnimationView animationNamed:'animation3.json'];
animationView3.loopAnimation = YES;
[animationView3 play];

[self.view addSubview:animationView1];
[self.view addSubview:animationView2];
[self.view addSubview:animationView3];

上述代码创建了三个 LottieAnimationView 实例,并将它们添加到视图中。您需要将 'animation1.json'、'animation2.json' 和 'animation3.json' 替换为实际的 JSON 文件名。

最后,将动画视图添加到视图层次结构中,以便它们可以在屏幕上显示出来。

请注意,您还可以设置其他属性,例如动画的位置、大小和循环等。

希望这可以帮助您加载和显示 Lottie 动画!

iOS Lottie 动画加载:使用 Objective-C 加载三个 JSON 动画

原文地址: https://www.cveoy.top/t/topic/qyBB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录