Last active
August 27, 2024 10:40
-
-
Save amannayak0007/e8fb74843ba6b4ed64c3761777fd8a01 to your computer and use it in GitHub Desktop.
Animated gradient background
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 SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
AnimatedBackground().edgesIgnoringSafeArea(.all) | |
.blur(radius: 50) | |
} | |
} | |
struct AnimatedBackground: View { | |
@State var start = UnitPoint(x: 0, y: -2) | |
@State var end = UnitPoint(x: 4, y: 0) | |
let timer = Timer.publish(every: 1, on: .main, in: .default).autoconnect() | |
let colors = [Color.blue, Color.red, Color.purple, Color.pink, Color.yellow, Color.green, Color.orange] | |
var body: some View { | |
LinearGradient(gradient: Gradient(colors: colors), startPoint: start, endPoint: end) | |
.animation(Animation.easeInOut(duration: 6).repeatForever()) | |
.onReceive(timer, perform: { _ in | |
self.start = UnitPoint(x: 4, y: 0) | |
self.end = UnitPoint(x: 0, y: 2) | |
self.start = UnitPoint(x: -4, y: 20) | |
self.start = UnitPoint(x: 4, y: 0) | |
}) | |
} | |
} |
looks beautiful
Smooth!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nimated gradient background in SwiftUI