2017-09-23 6 views
0

でアニメーションを取得できません私は「このLottie:名前

var loadingView = LOTAnimationView(name: "preloader") 

のようなアニメーションを取得しようとしているとき、私はLottie 2.1.3、XCodeの9およびIOS 11

を使用していますメートルこのエラーを取っ:+ [LOTComposition animationNamed:inBundleを:]:アニメーション

が見つかりましたが、以下のようなアニメーションを取得することは正常に動作しない

var loadingView = LOTAnimationView(filePath: "/Users/username/Git/iOS/Swift/LottieTest/LottieTest/preloader.json") 

私はpreloader.jsonを使用しています https://www.lottiefiles.com/storage/datafiles/Hhw0wgYmETDTkxW/data.json

私はここで間違っていますか?

答えて

0

問題。偶然、それは私のせいだった。あなたは次の操作を行う必要はありLOTAnimationView(name: "name") initメソッドを使用するためには ... Xcodeプロジェクトで

、その後、検査員(Xcodeのの右パネル)で、あなたのpreLoader.jsonのファイルをクリックしてチェックボックスをクリックしますターゲットメンバーシップ内のプロジェクトの名前

1

非常に興味深いですが、jsonファイルを使用するなどの他のinitメソッドを使用したいですか?

私はLottieのドキュメントをチェックしましたが、この初期化機能の背後にある説明を見つけることができませんLOTAnimationView(name: "name")。 Lottieの例でわかるように、LottieLogo.jsonファイルは、あなたの質問で提示したjsonファイルと私のプロジェクトの自分のjsonファイルとは異なるデータを持っています。

それにもかかわらず、ちょうどあなたのプロジェクトにあなたのJSONファイルを追加し、それを読み、Lottieのこのinit関数を使う - >LOTAnimationView(json: jsonObject)

私はGPKithttps://github.com/glennposadas/gpkit-iosと呼ばれる私の小さなプロジェクトにJSONファイルを読み取るための機能を作った:D

そして、そのようLottieのために上記の機能を使用して
public class GPJSONReader { 

    /** Get the whole JSON object from a file 
    * @returns an optional dictionary [String: Any]? 
    */ 

    public class func readJson(fileName: String, withBlock completion: ([String : Any]?) -> Void) { 
     do { 
      if let file = Bundle.main.url(forResource: fileName, withExtension: "json") { 
       let data = try Data(contentsOf: file) 
       let json = try JSONSerialization.jsonObject(with: data, options: []) 
       if let object = json as? [String : Any] { 
        GPLog(classSender: self, log: "JSON found as dictionary") 
        completion(object) 
       } else { 
        GPLog(classSender: self, log: "JSON is invalid") 
        completion(nil) 
       } 
      } else { 
       GPLog(classSender: self, log: "No file found!") 
       completion(nil) 
      } 
     } catch { 
      GPLog(classSender: self, log: error.localizedDescription) 
      completion(nil) 
     } 
    } 
} 

:私は私を解決し

// Animate here... 
GPJSONReader.readJson(fileName: "connecting", withBlock: { (jsonObject) in 
    if let jsonObject = jsonObject { 
     self.animationView = LOTAnimationView(json: jsonObject) 
     self.animationView.loopAnimation = true 
     self.animationView.play() 
    } 
}) 
+0

ありがとうございます。私はあなたが言うように他のinitメソッドを使用しなければならないと思います。私はlottieのバグがあると信じて、私はそれについての問題を開いた。 https://github.com/airbnb/lottie-ios/issues/430 –