今天準備試一下lottie這個牛牛的第三方,這個工具可以把從AE中導出的動畫的json文件解析成一個view供我們使用。lottie的地址是:https://github.com/airbnb/lottie-ios。
首先,我是準備直接在項目中導入這個框架。本以為很簡單的,可是意外還是發生了。導入框架lottie-ios之后,編譯通不過,報了九個錯誤。我明明是按照說明做得,這是怎么回事呢?開始各種google,最終沒有找到原因。具體錯誤信息如下:
CADisplayLink.m文件編譯出錯9個。
例如: Unknown type name 'CVDisplayLinkRef'; did you mean 'CADisplayLink'?
在搜索的過程中遇到一位博主,寫了使用lottie的相關東西,無奈之下,試著在他的文章下面把我的問題提問了一下,沒想到,他竟然回復了,非常的驚喜。他的回復如下:
iTerryWang: @睡醒的妞妞 我這邊也用你的方式集成了下,確實會報你說的錯,調查了下,是因為TARGET_OS_IPHONE 這種宏沒有生效。正常的情況,報錯那幾個文件是macOS平臺使用的。在編譯iOS平臺時,不應該被編譯。可以嘗試創建一個pch文件,把#import "TargetConditionals.h"這個加一下就可以正常編譯了。 不過還是推薦使用pods的方式集成。
我按照他的方法進行了實驗,真的編譯過了,很開心。在我開心的心情還沒有平靜的時候,一盆冷水又澆了個透心涼。
繼續集成lottie,使用推薦的方法:
LOTAnimationView animation = [LOTAnimationView animationNamed:@"loading"];
[self.view addSubview:animation];
[animation playWithCompletion:^(BOOL animationFinished) {
NSLog(@"動畫播放完成");
}];
然后編譯,崩潰啦!崩潰啦!崩潰啦!
崩潰信息如下:
運行,結果崩潰了,崩潰在LOTAnimationView的205行, resourceNotFoundException;這句話。控制臺給的崩潰信息是:** Terminating app due to uncaught exception 'ResourceNotFoundException', reason: '(null)'
。好無奈。
放棄使用直接導入的方式了,改用推薦的pod吧。
打開終端,正常的方式建立Podfile文件,寫入
platform:ios,'8.0'
target 'TestLottie' do
pod 'lottie-ios','~>1.5.0'
end
一直pod失敗,提示連接失敗443。以為是終端沒有使用翻墻代理導致的,所以花費了兩三個小時的時間在做終端代理的配置。配置了代理之后,還是報錯。為了驗證到底是哪里出了問題,先導入AFNetWorking試試,一試發現成功了,現在可以排除網絡原因了,應該是lottie這個三方沒找對。
錯誤信息如下:
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這個三方庫。
bogon:TestLottie aa$ pod search lottie-ios
[!] Unable to find a pod with name, author, summary, or description matching `lottie\-ios`
搜索不到這個三方庫。再搜一下AF試試吧。
bogon:TestLottie aa$ pod search AFNetWorking
[!] Unable to find a pod with name, author, summary, or description matching `AFNetWorking`
AF之前明明已經pod成功了,竟然也search不到,繼續查找原因。然后就找到了,說是本地庫的緩存有問題,在終端執行如下命令:
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,就真的找到了。
再次執行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
結果,又失敗了。。。。。
仔細對比之后發現,這次的錯誤和上次的錯誤竟然是一樣的!!!看來還是應該查找
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
這個錯誤。
尋找之后發現執行下面這個命令之后就好了:
bogon:TestLottie aa$ Git config --global http.postBuffer 524288000
再次執行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$
終于成功啦!!!!
后來再次查找原來的導入lottie的工程中的崩潰,發現是我忘記導入loading文件啦,實在是汗顏。人在著急的狀態下真的是檢驗抗壓和應變能力,這種錯誤實在是。。。。。以后不管事情多著急,還是應該靜下心來才能事半功倍。繼續加油吧!