Skip to content

A simple and lightweight framework to display looping images using native UIKit and SwiftUI

License

Notifications You must be signed in to change notification settings

mcrollin/Looping

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

➰Looping

License SwiftPM Support Carthage Support

What is Looping?

A simple and lightweight framework to display looping images using native UIKit and SwiftUI.

Supported formats

Out of the box, Looping supports 3 formats of animated and still images: GIF, APNG and HEIC.

To add WebP support, include the framework LoopingWebP, and enable it once:

import Looping
import LoopingWebP

LoopImage.enableWebP()

Dependencies

Next steps

  • CocoaPod support.
  • Unit tests coverage.
  • BackgroundBehavior (restart, stop, resume).
  • Progressive decoding option.
  • Native support on macOS, watchOS, tvOS.

Minimum deployment targets

  • iOS 11
  • macOS 10.15

Project requirements

  • Xcode 11 (swift 5.1)

Installation

SwiftPM

Swift Package Manager (SwiftPM) is dependency manager as well as a distribution tool.

From Xcode 11 onward, SwiftPM is natively integrated with Xcode. In File -> Swift Packages -> Add Package Dependency, search for WebPImage's repo URL.

If you're a framework author, you can add following the dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/znly/Looping.git", .from("0.1.0"))
]

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

To integrate Looping into your Xcode project using Carthage, specify it in your Cartfile:

github "znly/Looping" ~> 0.1.0

Usage

① Creating a LoopImage

The prefered method is to use init(data:, scale:). Default scale is 1.0.

import Looping

let imageData: Data
let image = try? LoopImage(data: imageData)

Additional convenience initializers are available: init(url:) and init(named:). Note: If the file name contains a scale factor (eg: @{1,2,3}x) it will be applied to the image.

② Displaying a LoopImage

Rendering happens on a background thread.

Using LoopView (UIKit)

import Looping

let image: LoopImage
let imageView = LoopView(loopImage: image)

loopView.contentMode = .scaleAspectFit
loopView.loopMode = .once

Using Loop (SwiftUI)

import Looping

let image: LoopImage

struct ContentView: View {
    var body: some View {
        Loop(image)
            .loopMode(.once)
            .resizable()
            .scaledToFit()
    }
}

③ Converting a LoopImage frame into a UIImage or CGImage

Using either the methods for a single frame LoopImage.cgImage(atFrame:) and LoopImage.image(atFrame:), or for a range of frames LoopImage.cgImages(atRange:).

For WebP images, since retrieving the image of at a specific frame requires to go over every intermediary frame to reconstruct the final image, it is recommended to call these methods outside of the main thread.

import Looping

let loopImage: LoopImage
let cgImage: CGImage = loopImage.cgImage()
let image: UIImage = loopImage.image() // alternatively you can use UIImage(loopImage: loopImage)

Documentation

Looping documentation can be found at znly.github.com/Looping.

Generated using SwiftDoc.

Authors

See AUTHORS for the list of contributors.

Credits

Assets used in the example app are taken from:

License

The Apache License version 2.0 (Apache2) - see LICENSE for more details.

Copyright © 2020 Zenly [email protected] @zenlyapp

About

A simple and lightweight framework to display looping images using native UIKit and SwiftUI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 98.1%
  • Objective-C 1.2%
  • Shell 0.7%