iOS开发 Lottie 三个json动画依次显示 怎么在 oc中使用 LOTAnimationView找不到
在OC中使用Lottie库,可以按照以下步骤来加载和显示三个json动画:
- 首先,确保已经将Lottie库添加到项目中。可以使用CocoaPods,在Podfile文件中添加以下行,并执行
pod install命令:
pod 'lottie-ios'
- 在需要显示动画的OC文件中,导入Lottie库的头文件:
#import <Lottie/Lottie.h>
- 创建一个LOTAnimationView对象,并设置其frame和动画文件:
LOTAnimationView *animationView = [[LOTAnimationView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
animationView.center = self.view.center;
[self.view addSubview:animationView];
// 设置第一个动画文件
NSString *animation1Path = [[NSBundle mainBundle] pathForResource:@"animation1" ofType:@"json"];
animationView.animation = [LOTAnimation animationWithFilePath:animation1Path];
// 播放第一个动画
[animationView play];
- 在动画播放完成的代理方法中,切换到下一个动画:
- (void)animationDidComplete:(LOTAnimationView *)animationView {
// 设置下一个动画文件
NSString *animation2Path = [[NSBundle mainBundle] pathForResource:@"animation2" ofType:@"json"];
animationView.animation = [LOTAnimation animationWithFilePath:animation2Path];
// 播放下一个动画
[animationView play];
}
- 重复步骤4,以加载和显示第三个动画。
确保将animation1.json、animation2.json和animation3.json这三个动画文件添加到项目的资源文件中,并根据实际文件名修改代码中的文件名。
以上是在OC中使用LOTAnimationView加载和显示三个json动画的基本步骤,希望对你有所帮助
原文地址: http://www.cveoy.top/t/topic/iSCb 著作权归作者所有。请勿转载和采集!