Swiftpack.co -  znly/Looping as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
znly/Looping
A simple and lightweight framework to display looping images using native UIKit and SwiftUI
.package(url: "https://github.com/znly/Looping.git", from: "1.1.2")

➰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 hello@zen.ly @zenlyapp

GitHub

link
Stars: 19
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Related Packages

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API