Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Lottie animation coder which use SDAnimatedImageView instead of LOTAnimationView for bitmap rendering

License

NotificationsYou must be signed in to change notification settings

SDWebImage/SDWebImageLottieCoder

Repository files navigation

CI StatusVersionLicensePlatformSwiftPM compatibleCarthage compatible

What's for

This is a coder plugin forLottie Animation format.

Differences

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.

SDWebImageLottiePlugin

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.

SDWebImageLottieCoder

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.

Example

To run the example project, clone the repo, and runpod install from the Example directory first.

Requirements

  • iOS 9+
  • macOS 10.11+
  • tvOS 9.0+
  • watchOS 2.0+
  • Xcode 11+

Installation

CocoaPods

SDWebImageLottieCoder is available throughCocoaPods. To installit, simply add the following line to your Podfile:

pod'SDWebImageLottieCoder'

Carthage

SDWebImageLottieCoder is available throughCarthage.

github "SDWebImage/SDWebImageLottieCoder"

Swift Package Manager (Xcode 11+)

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'

Usage

Add Coder

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)

Loading

  • Objective-C
// Lottie json loadingNSURL *lottieURL;UIImageView *imageView;[imageViewsd_setImageWithURL:lottieURL];
  • Swift
// Lottie json loadingletlottieURL:URLletimageView:UIImageViewimageView.sd_setImage(with: lottieURL)

Animation and Size

  • 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])

Decoding

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])

Screenshot

These Lottie animation stickers are fromlottiefiles-telegram

Author

DreamPiggy,lizhuoli1126@126.com

License

SDWebImageLottieCoder is available under the MIT license. See the LICENSE file for more info.

Thanks

About

A Lottie animation coder which use SDAnimatedImageView instead of LOTAnimationView for bitmap rendering

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp