今天準(zhǔn)備試一下lottie這個(gè)牛牛的第三方,這個(gè)工具可以把從AE中導(dǎo)出的動(dòng)畫的json文件解析成一個(gè)view供我們使用。lottie的地址是:https://github.com/airbnb/lottie-ios。
首先,我是準(zhǔn)備直接在項(xiàng)目中導(dǎo)入這個(gè)框架。本以為很簡單的,可是意外還是發(fā)生了。導(dǎo)入框架lottie-ios之后,編譯通不過,報(bào)了九個(gè)錯(cuò)誤。我明明是按照說明做得,這是怎么回事呢?開始各種google,最終沒有找到原因。具體錯(cuò)誤信息如下:
CADisplayLink.m文件編譯出錯(cuò)9個(gè)。
例如: Unknown type name 'CVDisplayLinkRef'; did you mean 'CADisplayLink'?
在搜索的過程中遇到一位博主,寫了使用lottie的相關(guān)東西,無奈之下,試著在他的文章下面把我的問題提問了一下,沒想到,他竟然回復(fù)了,非常的驚喜。他的回復(fù)如下:
iTerryWang: @睡醒的妞妞 我這邊也用你的方式集成了下,確實(shí)會(huì)報(bào)你說的錯(cuò),調(diào)查了下,是因?yàn)門ARGET_OS_IPHONE 這種宏沒有生效。正常的情況,報(bào)錯(cuò)那幾個(gè)文件是macOS平臺(tái)使用的。在編譯iOS平臺(tái)時(shí),不應(yīng)該被編譯。可以嘗試創(chuàng)建一個(gè)pch文件,把#import "TargetConditionals.h"這個(gè)加一下就可以正常編譯了。 不過還是推薦使用pods的方式集成。
我按照他的方法進(jìn)行了實(shí)驗(yàn),真的編譯過了,很開心。在我開心的心情還沒有平靜的時(shí)候,一盆冷水又澆了個(gè)透心涼。
繼續(xù)集成lottie,使用推薦的方法:
LOTAnimationView animation = [LOTAnimationView animationNamed:@"loading"];
[self.view addSubview:animation];
[animation playWithCompletion:^(BOOL animationFinished) {
NSLog(@"動(dòng)畫播放完成");
}];
然后編譯,崩潰啦!崩潰啦!崩潰啦!
崩潰信息如下:
運(yùn)行,結(jié)果崩潰了,崩潰在LOTAnimationView的205行, resourceNotFoundException;這句話。控制臺(tái)給的崩潰信息是:** Terminating app due to uncaught exception 'ResourceNotFoundException', reason: '(null)'
。好無奈。
放棄使用直接導(dǎo)入的方式了,改用推薦的pod吧。
打開終端,正常的方式建立Podfile文件,寫入
platform:ios,'8.0'
target 'TestLottie' do
pod 'lottie-ios','~>1.5.0'
end
一直pod失敗,提示連接失敗443。以為是終端沒有使用翻墻代理導(dǎo)致的,所以花費(fèi)了兩三個(gè)小時(shí)的時(shí)間在做終端代理的配置。配置了代理之后,還是報(bào)錯(cuò)。為了驗(yàn)證到底是哪里出了問題,先導(dǎo)入AFNetWorking試試,一試發(fā)現(xiàn)成功了,現(xiàn)在可以排除網(wǎng)絡(luò)原因了,應(yīng)該是lottie這個(gè)三方?jīng)]找對(duì)。
錯(cuò)誤信息如下:
bogon:TestLottie aa$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (3.1.0)
Installing lottie-ios (1.5.0)
[!] Error installing lottie-ios
[!] /usr/bin/git clone https://github.com/airbnb/lottie-ios.git /var/folders/yb/20c1c4sx0q91yqvzlr92n_p80000gp/T/d20170310-59137-kam3xz --template= --single-branch --depth 1 --branch 1.5.0
Cloning into '/var/folders/yb/20c1c4sx0q91yqvzlr92n_p80000gp/T/d20170310-59137-kam3xz'...
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
然后我想到先search一下看看能否找到lottie這個(gè)三方庫。
bogon:TestLottie aa$ pod search lottie-ios
[!] Unable to find a pod with name, author, summary, or description matching `lottie\-ios`
搜索不到這個(gè)三方庫。再搜一下AF試試吧。
bogon:TestLottie aa$ pod search AFNetWorking
[!] Unable to find a pod with name, author, summary, or description matching `AFNetWorking`
AF之前明明已經(jīng)pod成功了,竟然也search不到,繼續(xù)查找原因。然后就找到了,說是本地庫的緩存有問題,在終端執(zhí)行如下命令:
bogon:TestLottie aa$ rm ~/Library/Caches/CocoaPods/search_index.json
再次search,真的成功了!
bogon:TestLottie aa$ pod search AFNetworking
Creating search index for spec repo 'master'.. Done!
再次搜索search lottie,就真的找到了。
再次執(zhí)行install
bogon:TestLottie aa$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (3.1.0)
Installing lottie-ios (1.5.0)
[!] Error installing lottie-ios
[!] /usr/bin/git clone https://github.com/airbnb/lottie-ios.git /var/folders/yb/20c1c4sx0q91yqvzlr92n_p80000gp/T/d20170310-59225-l8vqf0 --template= --single-branch --depth 1 --branch 1.5.0
Cloning into '/var/folders/yb/20c1c4sx0q91yqvzlr92n_p80000gp/T/d20170310-59225-l8vqf0'...
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
結(jié)果,又失敗了。。。。。
仔細(xì)對(duì)比之后發(fā)現(xiàn),這次的錯(cuò)誤和上次的錯(cuò)誤竟然是一樣的!!!看來還是應(yīng)該查找
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
這個(gè)錯(cuò)誤。
尋找之后發(fā)現(xiàn)執(zhí)行下面這個(gè)命令之后就好了:
bogon:TestLottie aa$ Git config --global http.postBuffer 524288000
再次執(zhí)行install,
bogon:TestLottie aa$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (3.1.0)
Installing lottie-ios 1.5.0 (was 1.0.4)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
bogon:TestLottie aa$
終于成功啦!!!!
后來再次查找原來的導(dǎo)入lottie的工程中的崩潰,發(fā)現(xiàn)是我忘記導(dǎo)入loading文件啦,實(shí)在是汗顏。人在著急的狀態(tài)下真的是檢驗(yàn)抗壓和應(yīng)變能力,這種錯(cuò)誤實(shí)在是。。。。。以后不管事情多著急,還是應(yīng)該靜下心來才能事半功倍。繼續(xù)加油吧!