You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//pod 'lottie-ios'
// 1. Create the AnimationView
privatevaranimationView:AnimationView?overridefunc viewDidLoad(){
super.viewDidLoad()
// 2. Start AnimationView with animation name (without extension)
animationView =.init(name:"Name of Json File")
animationView!.frame = view.bounds
// 3. Set animation content mode
animationView!.contentMode =.scaleAspectFit
// 4. Set animation loop mode
animationView!.loopMode =.loop
// 5. Adjust animation speed
animationView!.animationSpeed =0.5
view.addSubview(animationView!)
// 6. Play animation
animationView!.play()}
enumProgressKeyFrames:CGFloat{case start =140case end =187case complete =240}privatevarprogressView:AnimationView?overridefunc viewDidLoad(){
super.viewDidLoad()
// make sure the name of the animation matches the imported file
progressView =.init(name:"download")
progressView!.frame = view.bounds
progressView!.contentMode =.scaleAspectFit
view.addSubview(progressView!)}overridefunc viewDidAppear(_ animated:Bool){
super.viewDidAppear(animated)startProgress()}privatefunc startProgress(){
// play from frame 0 to the start download of progress
progressView?.play(fromFrame:0, toFrame:ProgressKeyFrames.start.rawValue, loopMode:.none){[weak self](_)inself?.startDownload()}}
// progress from 0 to 100%
privatefunc startDownload(){
// play animation from start to end of download progress
progressView?.play(fromFrame:ProgressKeyFrames.start.rawValue, toFrame:ProgressKeyFrames.end.rawValue, loopMode:.none){[weak self](_)inself?.endDownload()}}
// download is completed, we show the completion state
privatefunc endDownload(){
// download is completed, we show the completion state
progressView?.play(fromFrame:ProgressKeyFrames.end.rawValue, toFrame:ProgressKeyFrames.complete.rawValue, loopMode:.none)}
How to run a demo app
Download the source code by cloning this repository
Install the pods by running
pod install
Open the xcworkspace file with the latest version of Xcode