Lottie is a mobile library for iOS that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile!
This library is a port of https://github.com/Baseflow/LottieXamarin/ to .NET 8 but limited to iOS.
Lottie supports iOS 8 and above. Lottie animations can be loaded from bundled JSON or from a URL
The simplest way to use it is with LOTAnimationView:
LOTAnimationView animation = LOTAnimationView.AnimationNamed("LottieLogo1");
this.View.AddSubview(animation);
animation.PlayWithCompletion((animationFinished) => {
// Do Something
});
//You can also use the awaitable version
//var animationFinished = await animation.PlayAsync();
Or you can load it programmatically from a NSUrl
LOTAnimationView animation = new LOTAnimationView(new NSUrl(url));
this.View.AddSubview(animation);
Lottie supports the iOS UIViewContentModes
ScaleAspectFit and ScaleAspectFill
You can also set the animation progress interactively.
CGPoint translation = gesture.GetTranslationInView(this.View);
nfloat progress = translation.Y / this.View.Bounds.Size.Height;
animationView.AnimationProgress = progress;
Want to mask arbitrary views to animation layers in a Lottie View? Easy-peasy as long as you know the name of the layer from After Effects
UIView snapshot = this.View.SnapshotView(afterScreenUpdates: true);
lottieAnimation.AddSubview(snapshot, layer: "AfterEffectsLayerName");
Lottie comes with a UIViewController
animation-controller for making custom viewController transitions!
#region View Controller Transitioning
public class LOTAnimationTransitionDelegate : UIViewControllerTransitioningDelegate
{
public override IUIViewControllerAnimatedTransitioning GetAnimationControllerForPresentedController(UIViewController presented, UIViewController presenting, UIViewController source)
{
LOTAnimationTransitionController animationController =
new LOTAnimationTransitionController(
animation: "vcTransition1",
fromLayer: "outLayer",
toLayer: "inLayer");
return animationController;
}
public override IUIViewControllerAnimatedTransitioning GetAnimationControllerForDismissedController(UIViewController dismissed)
{
LOTAnimationTransitionController animationController =
new LOTAnimationTransitionController(
animation: "vcTransition2",
fromLayer: "outLayer",
toLayer: "inLayer");
return animationController;
}
}
#endregion
If your animation will be frequently reused, LOTAnimationView
has an built in LRU Caching Strategy.
Linear Interpolation
Bezier Interpolation
Hold Interpolation
Rove Across Time
Spatial Bezier
Transform Anchor Point
Transform Position
Transform Scale
Transform Rotation
Transform Opacity
Path
Opacity
Multiple Masks (additive)
Multiple Parenting
Nulls
Rectangle (All properties)
Ellipse (All properties)
Polystar (All properties)
Polygon (All properties. Integer point values only.)
Path (All properties)
Anchor Point
Position
Scale
Rotation
Opacity
Group Transforms (Anchor point, position, scale etc)
Multiple paths in one group
Stroke Color
Stroke Opacity
Stroke Width
Line Cap
Dashes
Fill Color
Fill Opacity
Trim Paths Start
Trim Paths End
Trim Paths Offset
File github issues for anything that is unexpectedly broken. If an After Effects file is not working, please attach it to your issue. Debugging without the original file is much more difficult.