【问题标题】:Lottie for iOS Example?iOS 的 Lottie 示例?
【发布时间】: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


【解决方案1】:

我在自己的动画中看到过一些类似的问题。

首先,确保您的子视图在显示时具有有效的框架。我没有深入研究它,但有时在我将视图约束正确添加到动画视图之前我什么都看不到。

其次,仔细检查您的动画以确保它不依赖图像资源,因为目前不支持。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    相关资源
    最近更新 更多