Open-source project
onevcat/APNGKit avatar
onevcat/APNGKit

onevcat/APNGKit: playing APNG on Apple platforms with a throwing loader and a UIView subclass

High performance and delightful way to play with APNG format in iOS.

2,276 stars201 forksSwiftMIT

At a glance

What is it?
APNGKit is a Swift framework that loads and displays APNG images on iOS, macOS and tvOS. Its API is small and throwing, its view is a plain UIView or NSView subclass, and its install floor is old enough to cover almost any app.
Who is it for?
Use APNGKit if you are building an Apple-platform app and want animated PNG with 24-bit color and 8-bit transparency instead of GIF, with the loader failing loudly through throws. Look elsewhere if you need a Linux or Android target, or if you want a drop-in UIImageView replacement in Interface Builder.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 157 days ago.
What is it written in?
Mainly Swift, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • onevcat/APNGKit2,276 ★ · +1
Star history
Repository2026-10-082026-11-25
onevcat/APNGKit2.3k2.3k

1 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

An APNG file degrades to a still PNG where the format is unsupported

APNG extends PNG with animation, similar to an animated GIF, but it keeps 24-bit images and 8-bit transparency that GIF cannot hold. The README says the file size is comparable to a GIF, or even smaller if the file is created carefully. The format consists of a standard PNG header, so a platform without APNG support recognizes it as an ordinary PNG and shows its first frame as a static image.

That fallback is the safe part of choosing APNGKit. It is also a limit worth knowing: outside code paths that understand the animation chunks, your asset simply becomes a picture. The README admits APNG is a rebel format that the PNG group did not accept, though many vendors do. It notes Safari support on desktop and mobile, a WebKit core addition, and that Edge and Chrome were considering support when the text was written. The author's competing format for context, MNG, is described as so complex that it was almost universally rejected.

The install floor is iOS 9.0, macOS 10.11 and tvOS 9.0, and Swift Package Manager is the preferred route

The stated requirement is iOS 9.0+, macOS 10.11+ and tvOS 9.0+. Those are very low targets, so the constraint will rarely bite, but it also says nothing about newer platforms, and visionOS and watchOS are not mentioned.

Swift Package Manager is called the recommended way. In Xcode you choose File > Swift Packages > Add Package Dependency, enter https://github.com/onevcat/APNGKit.git and pick Up to Next Major with 2.0.0. The repository carries both Package.swift and [email protected], so the manifest is split by toolchain version. CocoaPods is the second route and needs a Podfile with a pinned major version:

ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'your_app' do
  pod 'APNGKit', '~> 2.0'
end

After pod install you must open the xcworkspace, not the xcodeproj. A Carthage badge appears in the README header, but no Carthage instructions appear in the text.

Every APNGImage initializer throws, so a bad file is an error you must handle

There are three ways to build an APNGImage: by name from the main bundle, from a file URL, and from raw Data that may come from disk or the network. The README states plainly that all initializers are throwable. If anything goes wrong while creating the image, the failure is explicit and you get a chance to handle it, which beats a silent nil.

swift
// Load an APNG image from file in main bundle
var image = try APNGImage(named: "your_image")

The consequence is that every call site needs try, either inside a do-catch or in a throwing function. The README's file example has a trap worth catching: it binds a variable called url from Bundle.main.url and then passes an identifier called path to the fileURL initializer. Copy-pasting that block will not compile until you pass the url you actually bound. The README also promises a later section on error handling, but the text cuts off before it.

APNGImageView is a UIView subclass, so a UIImageView in Interface Builder will not work

An APNGImage is only the data model. To show it, you create an APNGImageView with that image and add it to your view hierarchy. The view is a subclass of UIView on iOS and tvOS or NSView on macOS:

swift
let image: APNGImage = ... // You already have an APNG image object.

let imageView = APNGImageView(image: image)
view.addSubview(imageView)

In a XIB or Storyboard the README is emphatic. Drag a UIView or NSView onto the canvas and change its class to APNGImageView. Do not drag a UIImageView or NSImageView. After that you can connect an IBOutlet and set the image property as usual. Because the class is not an image view subclass, any code that expects a UIImageView, for example a generic helper that sets its image, cannot take an APNGImageView without an adapter.

Playback starts immediately unless you switch off autoStartAnimationWhenSetImage first

The animation plays automatically as soon as the image view receives a valid APNG image. To control the start yourself, set autoStartAnimationWhenSetImage to false before assigning the image, then call startAnimating when you want it to run:

swift
let imageView = APNGImageView(frame: .zero)
imageView.autoStartAnimationWhenSetImage = false
imageView.image = image

// Start the animation manually:
imageView.startAnimating()

Order matters here. Set the property after the image and the animation has already begun. This is the knob for screens where an animation should wait for a user action or for the view to appear, and the README gives no other autoplay option in the part that survives.

Loop counts come from the file, and finishing leaves you on the last frame

APNG stores a play loop count, exposed as numberOfPlays on APNGImage, and APNGKit respects it by default. When numberOfPlays is nil the animation plays forever. If it is a limited non-zero value, the animation stops at the final frame once the count is reached, so the view does not snap back to the first frame.

Two delegate hooks report progress. onOnePlayDone fires at the end of each loop and passes the count, while onAllPlaysDone fires when the whole animation is finished:

swift
imageView.onAllPlaysDone.delegate(on: self) { (self, _) in
    print("All done.")
}

The delegate(on:) call takes self as an explicit parameter in the closure. A file with an infinite loop count never triggers onAllPlaysDone, because it never finishes, so code that waits on it to dismiss a splash animation would hang on such an asset.

Streaming is the default load mode, and the README is cut off before explaining its cost

The README states that APNGKit loads the data in a streaming way by default, and the surviving text stops mid-sentence there. What a reader can verify from the repository is limited to its layout: Source and Tests folders, a Demo project with iOS and macOS targets, a CHANGELOG.md, an APNGKit.podspec and a fastlane folder. For the exact trade-offs of streaming, such as memory against decode timing, open CHANGELOG.md and the source before relying on it.

On upkeep, the repository is not archived and its last push was on 2026-06-22, the same day as release 2.4.0. Earlier releases are 2.3.0 from 2024-03-19 and 2.2.5 from 2023-12-11, so the gap between the last two tags was over two years. The license is MIT. For a library whose API surface is this small, a slow release cadence is expected, but it also means a bug you hit may wait for the next tag.

Editorial conclusion

Use APNGKit if you are building an Apple-platform app and want animated PNG with 24-bit color and 8-bit transparency instead of GIF, with the loader failing loudly through throws. Look elsewhere if you need a Linux or Android target, or if you want a drop-in UIImageView replacement in Interface Builder. Before adopting it, check that your minimum deployment target is iOS 9.0, macOS 10.11 or tvOS 9.0 or higher and that your assets really are APNG files.

Frequently asked questions

Is APNG better than GIF in APNGKit?

The README argues yes on quality: APNG supports 24-bit images and 8-bit transparency that GIF does not. File size is comparable to a GIF, or even smaller if the file is created carefully.

How do I open an APNG file with APNGKit?

Create an APNGImage with try APNGImage(named:), a file URL initializer or APNGImage(data:), then show it in an APNGImageView. A platform without APNG support shows the file as a normal PNG with its first frame.

What is APNG used for in APNGKit?

APNG is animated PNG, working similarly to animated GIF files. APNGKit loads and displays these images in iOS and macOS apps, with a throwing API and an APNGImageView.

Official sources

  1. Issues
  2. License: MIT
  3. onevcat/APNGKit on GitHub
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/onevcat-apngkit.svg)](https://hysenlabs.com/projects/onevcat-apngkit)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/onevcat-apngkit.svg)](https://hysenlabs.com/projects/onevcat-apngkit)

Was this useful?