Created
August 31, 2021 06:59
-
-
Save amosgyamfi/61419e25bf0a2ff6d502d53e8c609afe 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
// | |
// ContentView.swift | |
// BgColorKeyframeAnimkation | |
// | |
// Created by Amos Gyamfi on 14.8.2021. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@State private var switchColor = Color(.red) | |
var body: some View { | |
if #available(iOS 15.0, *) { | |
ZStack { | |
Rectangle() | |
.ignoresSafeArea() | |
// Primary colors: Initial keyframe | |
.foregroundColor(switchColor) | |
.task { | |
withAnimation(Animation.easeInOut(duration: 1).delay(2)){ | |
switchColor = Color(.yellow) | |
} | |
withAnimation(Animation.easeInOut(duration: 1).delay(4)){ | |
switchColor = Color(.blue) | |
} | |
// Secondary colors | |
withAnimation(Animation.easeInOut(duration: 1).delay(6)){ | |
switchColor = Color(.orange) | |
} | |
withAnimation(Animation.easeInOut(duration: 1).delay(8)){ | |
switchColor = Color(.green) | |
} | |
withAnimation(Animation.easeInOut(duration: 1).delay(10)){ | |
switchColor = Color(.purple) | |
} | |
} | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment