dotLottie 0.1.7

dotLottie 0.1.7

Evandro Hoffmann 维护。



 
依赖关系
dotLottieLoader~> 0.1.3
lottie-ios~> 3.2.0
 

dotLottie 0.1.7

  • eharrison

dotLottie-ios

CI Status Version License Platform

介绍 dotLottie

dotLottie 是一个开源文件格式,它可以聚合一个或多个 Lottie 文件和相关的资源到一个单个文件中。它们是用 Deflate 压缩方法压缩的 ZIP 归档,并且文件扩展名是 ".lottie"。

dotlottie.io 查看文档、常见问题、帮助、示例等

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install

要求

  • Swift 5.0
  • iOS 9
  • macOS 10.12
  • tvOS 10.0

安装

CocoaPods

dotLottie-ios 可以通过 CocoaPods 获取。要安装它,只需在 Podfile 中添加以下行

pod 'dotLottie'

Swift 包管理器

.package(url: "https://github.com/dotlottie/dotlottie-ios.git", from: "0.1.7")

使用 dotLottie

import Lottie
import dotLottie
启用日志
DotLottie.isLogEnabled = true
从本地文件加载
let animationView = AnimationView()

DotLottie.load(name: "animation") { (animation) in
    if let animation = animation {
        self.animationView.animation = animation
        self.animationView.bounds = CGRect(x: 0, y: 0, width: 300, height: 300)
        self.animationView.center = self.view.center

        self.view.addSubview(self.animationView)
        self.animationView.play()
    }else{
       print("Error loading .lottie")
    }
}
从远程文件加载
let animationView = AnimationView()

DotLottie.load(from: URL(string:"https://dotlottie.io/sample_files/animation.lottie")!){ (animation) in
    if let animation = animation {
        self.animationView.animation = animation
        self.animationView.bounds = CGRect(x: 0, y: 0, width: 300, height: 300)
        self.animationView.center = self.view.center

        self.view.addSubview(self.animationView)
        self.animationView.play()
    }else{
       print("Error loading .lottie")
    }
}

SwiftUI

从本地文件加载数据
import SwiftUI
import dotLottie

struct LocalAnimationView: View {
    @State var name: String
    @State var play: Int = 1
    
    var body: some View {
        DotLottieView(name: name, play: self.$play, onCompleted: { completed in
            // handle completion
        })
        .frame(height:200)
    }
}
从远程源加载数据文件
import SwiftUI
import dotLottie

struct RemoteAnimationView: View {
    @State var url: URL
    @State var play: Int = 1
    
    var body: some View {
        DotLottieView(url: url, play: self.$play, onCompleted: { completed in
            // handle completion
        })
        .frame(height:200)
    }
}

作者

Evandro Harrison Hoffmann | [email protected]

许可协议

dotLottie-ios 在 MIT 许可下可用。详见 LICENSE 文件获取更多信息。