Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created August 31, 2021 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/61419e25bf0a2ff6d502d53e8c609afe to your computer and use it in GitHub Desktop.
Save amosgyamfi/61419e25bf0a2ff6d502d53e8c609afe to your computer and use it in GitHub Desktop.
//
// 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