Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daprice/zoetrope
Create frame-based animations using SwiftUI TimelineView, including support for animated images
https://github.com/daprice/zoetrope
animation gif gif-animation swift-package swiftui swiftui-animation
Last synced: 3 months ago
JSON representation
Create frame-based animations using SwiftUI TimelineView, including support for animated images
- Host: GitHub
- URL: https://github.com/daprice/zoetrope
- Owner: daprice
- License: mit
- Created: 2024-06-29T23:06:20.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-07-05T21:12:32.000Z (7 months ago)
- Last Synced: 2024-10-07T17:16:20.635Z (4 months ago)
- Topics: animation, gif, gif-animation, swift-package, swiftui, swiftui-animation
- Language: Swift
- Homepage:
- Size: 75.2 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ``Zoetrope``
Create frame-based animations in SwiftUI, including support for animated images.
## OverviewZoetrope provides three native SwiftUI views:
- `FrameAnimator`: a versatile wrapper around TimelineView for creating frame-based animations
- `AnimatedImageView`: for playing back animated UIImage or NSImage instances
- `AsyncAnimatedImage`: loads and plays images from URLs, similar to SwiftUI's AsyncImage.All three views allow you to specify a start date to animate relative to. This allows you to synchronize playback across multiple views, or even multiple devices as long as their clocks are in sync.
> [!TIP]
> For example, social apps that support looping GIF avatars (like Mastodon/Fediverse clients) could use a profile's creation date as the animation start date. If two people in the same room were looking at the same profile or post, they'd see the avatars playing in sync between their devices. 🪄 Magic!### Image format support
On UIKit platforms (iOS, iPadOS, visionOS, tvOS, watchOS, Mac Catalyst), Zoetrope supports animated GIF, WebP, HEIC, or APNG files, all using native UIImage.
> [!NOTE]
> Support is provided using a special UIImage initializer that uses the native ImageIO framework to read those formats, storing any extra metadata (such as loop count and variable frame rate, if applicable) as Associated Objects on the UIImage instance itself. Zoetrope's image view can also play animated UIImage instances created using UIKit's built-in `UIImage.animatedImage` methods.On AppKit platforms (native macOS), Zoetrope relies on NSImage's built-in support for animated GIF files.
### Examples
`Sources/Views/FrameAnimator.swift` and `Sources/Views/AsyncAnimatedImage.swift` include Xcode previews with examples.