Last active
April 24, 2020 15:45
-
-
Save jobedylbas/51fa3fd0821f786a5dc4912cf488f274 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
struct AnimatedImage: View { | |
@State private var image: Image? | |
private let imageNames: [String] | |
var body: some View { | |
Group { | |
image? | |
.resizable() | |
.scaledToFit() | |
}.onAppear(perform: { | |
self.animate() | |
}) | |
} | |
private func animate() { | |
var imageIndex: Int = 0 | |
Timer.scheduledTimer(withTimeInterval: 0.025, repeats: true) { timer in | |
if imageIndex < self.imageNames.count { | |
self.image = Image(self.imageNames[imageIndex]) | |
imageIndex += 1 | |
} | |
else { | |
timer.invalidate() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment