我是相當新的動畫和我試圖讓下面的圖書館工作:使用bodymovin(https://github.com/bodymovin/bodymovin)Lottie的iOS示例?
https://github.com/airbnb/lottie-ios
它需要被創建在After Effects和出口爲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'中做它 – dan
謝謝,移動[testAnimation玩]和日誌viewDidAppear,它仍然是空白,控制檯說它正在播放。 – yousefnjr
我想我已經想通了,問題是我的data.json文件。我交換了其中一個示例動畫文件,並且能夠顯示它。也許我使用了不受支持的功能或其他功能,不知道。 – yousefnjr