Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created July 16, 2019 18:22
Show Gist options
  • Save Dimillian/42a19d45b349e1b3b26b6955c7965f95 to your computer and use it in GitHub Desktop.
Save Dimillian/42a19d45b349e1b3b26b6955c7965f95 to your computer and use it in GitHub Desktop.
struct ToggleButton: View {
@State private var isOn = false
var myAnimation: Animation {
.spring(mass: 1, stiffness: 150, damping: 10, initialVelocity: 20)
}
var body: some View {
Button(action: {
withAnimation(self.myAnimation) {
self.isOn.toggle()
}
}) {
Text("Press me")
}
.scaleEffect(isOn ? 1.5 : 1.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment