Lottie導入が一瞬だった件[備忘録]
Airbnb社が開発したライブラリ「Lottie」を使ってみました。
実装時間およそ10分です。
jsonファイルをダウンロード
上記ページから欲しいアニメーションを選択して右下のダウンロードボタンで取得。

cocoapodでインストール
def install_pods pod 'lottie-ios' end target 'taurus-ios-develop' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for taurus-ios-develop install_pods firebase end
Bridging-Headerの設定
通常通りBridging-Headerを追加して、#import <Lottie/Lottie.h>を追加します。

あとは実装
//
// ViewController.swift
// taurus-ios
//
// Created by yutaabe200 on 2018/12/21.
// Copyright © 2018 CUNELWORK.CO.,LTD. All rights reserved.
//
import UIKit
import Lottie
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let animationView = LOTAnimationView(name: "success.json")
animationView.frame = CGRect(x: self.view.bounds.width / 2 - 70,
y: self.view.bounds.height / 2 - 180,
width: 140,
height: 140)
animationView.loopAnimation = true
animationView.contentMode = .scaleAspectFit
animationView.animationSpeed = 1
self.view.addSubview(animationView)
animationView.play()
}
}

また、loopAnimationをfalseにして、下記のコードのようにするとアニメーション終了をフックできます。
animationView.play{ (finished) in
// Do Something
}
細かいプロパティなどはこちらにあるそうです。

詳細! Swift iPhoneアプリ開発入門ノート iOS12 + Xcode 10対応
- 作者: 大重美幸
- 出版社/メーカー: ソーテック社
- 発売日: 2018/11/03
- メディア: 単行本
- この商品を含むブログを見る