Skip to content

Instantly share code, notes, and snippets.

Avatar
🍉

Jobe Dylbas jobedylbas

🍉
View GitHub Profile
View ContentView.swift
struct ContentView: View {
var imageNames: [String] = ["img_0", "img_1"]
var body: some View {
AnimatedImage(imageNames: imageNames)
}
}
View AnimatedImage.swift
struct AnimatedImage: View {
@State private var image: Image?
private let imageNames: [String]
var body: some View {
Group {
image?
.resizable()
.scaledToFit()
}.onAppear(perform: {
View Animate.swift
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()
View AnimatedImage.swift
struct AnimatedImage: View {
@State private var image: Image?
private let imageNames: [String]
var body: some View {
image?
.resizable()
.scaledToFit()
}
}