Skip to content

Instantly share code, notes, and snippets.

@DarrenHurst
Created March 24, 2024 23:15
Show Gist options
  • Save DarrenHurst/b31d0fbad54ac1ed97c068c96e5033ab to your computer and use it in GitHub Desktop.
Save DarrenHurst/b31d0fbad54ac1ed97c068c96e5033ab to your computer and use it in GitHub Desktop.
SwiftUIHop Egg3
import SwiftUI
struct Egg3: View {
@State var openSpot: Int = 1
@State var image1Location: CGSize = CGSize()
@State var image2Location: CGSize = CGSize()
@State var image3Location: CGSize = CGSize()
@State var image4Location: CGSize = CGSize()
@State var opacityLevel: CGFloat = 0.1
let topLeft: CGSize = CGSize(width:-100, height:-100)
let topRight: CGSize = CGSize(width:100, height:-100)
let bottomLeft: CGSize = CGSize(width: -100, height: 100)
let bottomRight: CGSize = CGSize(width: 100, height: 100)
var image: Image = Image("easterbunnycabin")
let sign: Image = Image("EasterSign")
var body: some View {
ZStack {
image.resizable().scaleEffect(x:2,y:2,anchor: .topLeading).frame(width:200, height: 200).mask(Rectangle())
.offset(image1Location)
.opacity(opacityLevel)
.animation(.linear, value: opacityLevel)
.onTapGesture {
image1Location = topRight
image2Location = bottomRight
image3Location = topLeft
image4Location = bottomLeft
}
image.resizable().scaleEffect(x:2,y:2, anchor: .topTrailing).frame(width:200, height: 200).mask(Rectangle())
.offset(image2Location)
.onTapGesture {
if (image1Location == topRight) {
image1Location = topLeft
image2Location = topRight
image3Location = bottomLeft
image4Location = bottomRight
opacityLevel = 1.0
}
}
image.resizable().scaleEffect(x:2,y:2, anchor: .bottomLeading).frame(width:200, height: 200).mask(Rectangle())
.offset(image3Location)
image.resizable().scaleEffect(x:2,y:2, anchor: .bottomTrailing).frame(width:200, height: 200).mask(Rectangle())
.offset(image4Location)
sign.resizable()
.offset(y: opacityLevel == 1.0 ? 0 : 100)
.opacity(opacityLevel == 1.0 ? 1.0 : 0.0)
.animation(.interpolatingSpring(stiffness: 1.3, damping: 0.9), value: opacityLevel)
}.frame(width:400,height:400)
.onAppear() {
image1Location = bottomRight
image2Location = bottomLeft
image3Location = topRight
image4Location = topLeft
}
.mask(Rectangle())
}
}
struct Egg3_Previews: PreviewProvider {
static var previews: some View {
Egg3()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment