iOS开发 Lottie 加载三个json动画 oc代码
以下是一个使用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动画
原文地址: http://www.cveoy.top/t/topic/iSB5 著作权归作者所有。请勿转载和采集!