Created
August 31, 2019 07:55
-
-
Save laevandus/017d8ef4ac71aa8365501bd54e589369 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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