Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Last active October 19, 2020 05:47
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/1f3b832ec383f4ec4eba06e530fcf872 to your computer and use it in GitHub Desktop.
Save amosgyamfi/1f3b832ec383f4ec4eba06e530fcf872 to your computer and use it in GitHub Desktop.
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State private var topRotates = false
@State private var middleIsHidden = false
@State private var bottomRotates = false
var body: some View {
VStack(alignment: .center, spacing: 25){
Rectangle() // top
.frame(width: 120, height: 20)
.cornerRadius(4)
.rotationEffect(.degrees(topRotates ? 48 : 0), anchor: .leading)
Rectangle() // middle
.frame(width: 120, height: 20)
.cornerRadius(4)
.scaleEffect(middleIsHidden ? 0 : 1)
.opacity(middleIsHidden ? 0 : 1)
Rectangle() // bottom
.frame(width: 120, height: 20)
.cornerRadius(4)
.rotationEffect(.degrees(bottomRotates ? -48 : 0), anchor: .leading)
}.animation(
Animation.interpolatingSpring(stiffness: 300, damping: 15))
.onTapGesture {
self.topRotates.toggle()
self.bottomRotates.toggle()
self.middleIsHidden.toggle()
}
}
}
let ContentView_Previews = ContentView()
let vc = UIHostingController(rootView: ContentView_Previews)
PlaygroundPage.current.liveView = vc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment