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.
- Install Lottie Package in Xamarin.iOS project.
- Write code to play Animation in Controller file.
- using System;
- using Airbnb.Lottie;
- using UIKit;
-
- namespace demoiOS
- {
- public partial class ViewController : UIViewController
- {
- private LOTAnimationView lottieLogo;
- protected ViewController (IntPtr handle) : base (handle)
- {
-
- }
-
- public override void ViewDidLoad ()
- {
- base.ViewDidLoad ();
-
- this.lottieLogo = LOTAnimationView.AnimationNamed ("video_cam");
- this.lottieLogo.ContentMode = UIViewContentMode.ScaleAspectFill;
- this.lottieLogo.LoopAnimation = true;
- this.View.AddSubview (this.lottieLogo);
- }
-
- private void PlayLottieAnimation ()
- {
- this.lottieLogo.AnimationProgress = 0;
- this.lottieLogo.Play ();
- }
-
- public override void ViewWillAppear (bool animated)
- {
- base.ViewWillAppear (animated);
- this.lottieLogo.Play ();
- }
-
- public override void ViewDidDisappear (bool animated)
- {
- base.ViewDidDisappear (animated);
- this.lottieLogo.Pause ();
- }
-
- public override void DidReceiveMemoryWarning ()
- {
- base.DidReceiveMemoryWarning ();
-
- }
- }
- }
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.