【发布时间】:2017-02-10 18:55:36
【问题描述】:
我对动画还很陌生,我正在尝试使用以下库:https://github.com/airbnb/lottie-ios
它采用在 After Effects 中创建并使用 bodymovin (https://github.com/bodymovin/bodymovin) 导出为 JSON 的动画
我制作了一个简单的测试动画并将其导出为 JSON(称为 data.json)。我在 Xcode 中制作了一个简单的测试应用程序,添加了 Lottie 框架,并将 data.json 添加到包中。我只是想让动画在启动时显示,这就是我在 viewDidLoad 中的不工作:
NSString *myFilePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
NSData *myData = [NSData dataWithContentsOfFile:myFilePath];
NSError *error = nil;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:myData
options:kNilOptions
error:&error];
LOTAnimationView *testAnimation = [LOTAnimationView animationFromJSON:jsonDict];
[self.view addSubview:testAnimation];
[testAnimation play];
NSLog(@"subviews - %@", self.view.subviews);
NSLog(@"testanim - %@", testAnimation.description);
if (testAnimation.isAnimationPlaying)
{
NSLog(@"is playing");
}
我得到的只是一个空白的白色屏幕。在控制台中,我可以看到添加了子视图,以及来自 isAnimationPlaying 的日志。我还可以记录 jsonDict.description 并且我看到 JSON 在那里。我做错了什么?
这是我正在使用的 JSON 文件:http://s000.tinyupload.com/?file_id=15724557118327374873
【问题讨论】:
-
尝试在
viewDidAppear而不是viewDidLoad中进行操作 -
谢谢,已将 [testAnimation play] 和日志移至 viewDidAppear,但它仍然是空白的,但控制台说它正在播放。
-
我想我已经弄清楚了,问题出在我的 data.json 文件上。我交换了他们的一个示例动画文件,并且能够显示它。也许我使用了不受支持的功能或其他东西,不知道。
标签: ios objective-c xcode after-effects