Skip to content

Instantly share code, notes, and snippets.

@DarrenHurst
Last active March 28, 2024 12:49
Show Gist options
  • Save DarrenHurst/3f7e28474410e005ad9d8e60a80b7e3e to your computer and use it in GitHub Desktop.
Save DarrenHurst/3f7e28474410e005ad9d8e60a80b7e3e to your computer and use it in GitHub Desktop.
animation delay
@vrutberg
//
// box.swift
// Designer
//
// Created by Darren Hurst on 2024-03-27.
//
import SwiftUI
struct box: View {
@State var onAnimating: Bool = false
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 5.0)
.offset(x: onAnimating ? -10 : 0)
.fill(.blue)
.rotationEffect(.degrees(-5))
.opacity(0.5)
.shadow(radius: 5.0)
.frame(width: 50, height: 50)
.scaleEffect(onAnimating ? 1.5 : 1.0)
.offset(x: onAnimating ? -10 : -3)
.animation(.spring().delay(0.3), value: onAnimating)
RoundedRectangle(cornerRadius: 5.0)
.offset(x: onAnimating ? 10 : 0)
.fill(.green)
.rotationEffect(.degrees(5))
.shadow(radius: 5.0)
.opacity(0.5)
.frame(width: 50, height: 50)
.scaleEffect(onAnimating ? 1.5 : 1.0)
.offset(x: onAnimating ? 10 : 3)
.animation(.spring().delay(0.3), value: onAnimating)
RoundedRectangle(cornerRadius: 5.0)
.fill(.pink)
.frame(width: 50, height: 50)
.scaleEffect(onAnimating ? 1.5 : 1.0)
.onTapGesture {
onAnimating.toggle()
}
RoundedRectangle(cornerRadius: 5.0)
.stroke(.white)
.frame(width: 50, height: 50)
.onTapGesture {
onAnimating.toggle()
}
.background(Image(systemName: "doc.text.fill")
.resizable()
.scaledToFit()
.padding(5)
.onTapGesture {
onAnimating.toggle()
})
.scaleEffect(onAnimating ? 1.5 : 1.0)
}
.animation(.spring(), value: onAnimating)
.frame(width:200, height: 200)
}
}
struct box_Previews: PreviewProvider {
static var previews: some View {
box()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment