Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created August 31, 2019 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/017d8ef4ac71aa8365501bd54e589369 to your computer and use it in GitHub Desktop.
Save laevandus/017d8ef4ac71aa8365501bd54e589369 to your computer and use it in GitHub Desktop.
import Combine
import UIKit
final class ImageAnimator: ObservableObject {
private let scheduler: ImageFrameScheduler
init(imageURL: URL) {
self.scheduler = ImageFrameScheduler(url: imageURL)
}
@Published var image: CGImage?
func startAnimating() {
let isRunning = scheduler.start { [weak self] (index, image) in
self?.image = image
}
if isRunning == false {
print("Failed animate image at url \(scheduler.imageURL)")
}
}
func stopAnimating() {
scheduler.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment