- Notifications
You must be signed in to change notification settings - Fork23
A Lottie animation coder which use SDAnimatedImageView instead of LOTAnimationView for bitmap rendering
License
SDWebImage/SDWebImageLottieCoder
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a coder plugin forLottie Animation format.
We've already built one Lottie plugin, calledSDWebImageLottiePlugin.
The main difference for these two components, it'sHow we play animation, andWhat dependency we use. In order to reduce the code size for unnecessary dependency, we separate these into 2 different repos.
This lottie framework dependentlottie-ios, which is maintained by Airbnb.
This plugin can only play animation by using their ownLOTAnimationView.
Pros: It use vector rendering technology like Core Animation Layer, which means you can change your view dynamic size without lossing details or regenerate images.
Cons: Vector rendering is much slower than bitmap rendering. For small and massive lottie images, like emojis, small icons, this is not suitable.
This lottie framework dependentrlottie, which is maintained by Samsung.
This plugin can play animation on bothSDAnimatedImageView andUIImageView/NSImageView.
Pros: It use bitmap rendering, each animation frame are rendered into the rasterized bitmap, not vector images. You can also preload all frames into memory, to get the best performance and 60FPS. This is also easy to integrate to UIKit/AppKit native framework.
Cons: Bitmap rendering does not support dynamic size changes. Once you want larger images, you need re-decoding the source lottie JSON, which is time-consuming and RAM consuming.
To run the example project, clone the repo, and runpod install from the Example directory first.
- iOS 9+
- macOS 10.11+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 11+
SDWebImageLottieCoder is available throughCocoaPods. To installit, simply add the following line to your Podfile:
pod'SDWebImageLottieCoder'
SDWebImageLottieCoder is available throughCarthage.
github "SDWebImage/SDWebImageLottieCoder"SDWebImageLottieCoder is available throughSwift Package Manager.
letpackage=Package( dependencies:[.package(url:"https://github.com/SDWebImage/SDWebImageLottieCoder.git", from:"0.1")])
SDWebImageLottieCoder is available throughCocoaPods. To installit, simply add the following line to your Podfile:
pod'SDWebImageLottieCoder'
Before using SDWebImage to load Lottie json, you need to register the Lottie Coder to your coders manager. This step is recommended to be done after your App launch (like AppDelegate method).
- Objective-C
// Add coderSDImageLottieCoder *lottieCoder = [SDImageLottieCodersharedCoder];[[SDImageCodersManagersharedManager]addCoder:lottieCoder];
- Swift
// Add coderletlottieCoder=SDImageLottieCoder.sharedSDImageCodersManager.shared.addCoder(lottieCoder)
- Objective-C
// Lottie json loadingNSURL *lottieURL;UIImageView *imageView;[imageViewsd_setImageWithURL:lottieURL];
- Swift
// Lottie json loadingletlottieURL:URLletimageView:UIImageViewimageView.sd_setImage(with: lottieURL)
- Objective-C
// Lottie json loading on animated image viewNSURL *lottieURL;SDAnimatedImageView *imageView;CGSize pixelSize = CGSizeMake(300,300);[imageViewsd_setImageWithURL:lottieURLplaceholderImage:niloptions:0context:@{SDWebImageThumbnailPixelSize:@(pixelSize)}];
- Swift
// Lottie json loading on animated image viewletlottieURL:URLletimageView:SDAnimatedImageViewletpixelSize=CGSize(width:300, height:300)imageView.sd_setImage(with: lottieURL, placeholderImage:nil, options:[], contrext:[.thumbnailPixelSize: pixelSize])
You can decode lottie image into aniamted UIImage/NSImage as well. If the lottie images havereferenced external image resource, you can specify it as well.
- Objective-C
// Lottie image decodingNSData *lottieJSONData;NSBundle *imageBundle;// You can even download the external image from online to local path, then load the lottie animationUIImage *image = [[SDImageLottieCodersharedCoder]decodedImageWithData:lottieJSONDataoptions:@{SDImageCoderDecodeLottieResourcePath : imageBundle.resourcePath}];
- Swift
// Lottie image decodingletlottieJSONData:DataletimageBundle:Bundle // You can even download the external image from online to local path, then load the lottie animationletimage=SDImageWebPCoder.shared.decodedImage(with: lottieJSONData, options:[.lottieResourcePath: imageBundle.resourcePath])
These Lottie animation stickers are fromlottiefiles-telegram
DreamPiggy,lizhuoli1126@126.com
SDWebImageLottieCoder is available under the MIT license. See the LICENSE file for more info.
About
A Lottie animation coder which use SDAnimatedImageView instead of LOTAnimationView for bitmap rendering
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
