Animierte Pfadzeichnung mit Timer
Erstellt einen animierten Strichzeichnungseffekt mithilfe von Pfad- und zeitgesteuerten Statusaktualisierungen.
import SwiftUI
struct AnimatedPathExample: View {
@State private var progress: CGFloat = 0
var body: some View {
Path { path in
path.move(to: CGPoint(x: 20, y: 100))
path.addLine(to: CGPoint(x: 20 + (300 * progress), y: 100))
}
.stroke(Color.blue, lineWidth: 4)
.onAppear {
Timer.scheduledTimer(withTimeInterval: 0.02, repeats: true) { timer in
progress += 0.01
if progress >= 1 { timer.invalidate() }
}
}
.frame(height: 120)
.padding()
}
}