Lottie Animations In Xamarin.iOS

Today, I will give you some of the information on how to set up Lottie animation in Xamarin iOS.
 
Question: Why did I need to write this blog?

Answer:

I saw people were frustrated because Lottie was not working for them. With this post, I will try to explain step by step how to make it work.


Okay guys! Let's start it. Step by step, we will start and apply Lottie Animation in Xamarin.iOS.

In four steps, we are able to steup the Lottie Animation in Xamarin.iOS.
  1. Install Lottie Package in Xamarin.iOS project.
  2. Write code to play Animation in Controller file.
  1. using System;  
  2. using Airbnb.Lottie;  
  3. using UIKit;  
  4.   
  5. namespace demoiOS  
  6. {  
  7.     public partial class ViewController : UIViewController  
  8.     {  
  9.         private LOTAnimationView lottieLogo;  
  10.         protected ViewController (IntPtr handle) : base (handle)  
  11.         {  
  12.             // Note: this .ctor should not contain any initialization logic.  
  13.         }  
  14.   
  15.         public override void ViewDidLoad ()  
  16.         {  
  17.             base.ViewDidLoad ();  
  18.   
  19.             this.lottieLogo = LOTAnimationView.AnimationNamed ("video_cam");  
  20.             this.lottieLogo.ContentMode = UIViewContentMode.ScaleAspectFill;  
  21.             this.lottieLogo.LoopAnimation = true;  
  22.             this.View.AddSubview (this.lottieLogo);  
  23.         }  
  24.   
  25.         private void PlayLottieAnimation ()  
  26.         {  
  27.             this.lottieLogo.AnimationProgress = 0;  
  28.             this.lottieLogo.Play ();  
  29.         }  
  30.   
  31.         public override void ViewWillAppear (bool animated)  
  32.         {  
  33.             base.ViewWillAppear (animated);  
  34.             this.lottieLogo.Play ();  
  35.         }  
  36.   
  37.         public override void ViewDidDisappear (bool animated)  
  38.         {  
  39.             base.ViewDidDisappear (animated);  
  40.             this.lottieLogo.Pause ();  
  41.         }  
  42.   
  43.         public override void DidReceiveMemoryWarning ()  
  44.         {  
  45.             base.DidReceiveMemoryWarning ();  
  46.             // Release any cached data, images, etc that aren't in us  
  47.         }  
  48.     }  

Place that JSON file in Resources folder. The main point is to check its build action is to bundle Resources.
 
Compile your iOS project.

 
 
Feel free to comment if you are not able to figure out it.
 
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now