Created
February 11, 2022 21:13
-
-
Save amosgyamfi/df3eeade6979349bb60862b25e46dece 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 | |
// hamburger_to_close | |
// | |
// Created by Amos Gyamfi on 30.3.2021. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@State private var isRotating = false | |
@State private var isHidden = false | |
var body: some View { | |
VStack(spacing: 14){ | |
Rectangle() // top | |
.frame(width: 64, height: 10) | |
.cornerRadius(4) | |
.rotationEffect(.degrees(isRotating ? 48 : 0), anchor: .leading) | |
Rectangle() // middle | |
.frame(width: 64, height: 10) | |
.cornerRadius(4) | |
.scaleEffect(isHidden ? 0 : 1, anchor: isHidden ? .trailing: .leading) | |
.opacity(isHidden ? 0 : 1) | |
Rectangle() // bottom | |
.frame(width: 64, height: 10) | |
.cornerRadius(4) | |
.rotationEffect(.degrees(isRotating ? -48 : 0), anchor: .leading) | |
} | |
.onTapGesture { | |
withAnimation(.interpolatingSpring(stiffness: 300, damping: 15)){ | |
isRotating.toggle() | |
isHidden.toggle() | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
.preferredColorScheme(.dark) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment