Skip to content

Instantly share code, notes, and snippets.

@alexpaul
Created August 1, 2020 00:08
Show Gist options
  • Save alexpaul/e8f8857b58f0ee0d0269465807de772c to your computer and use it in GitHub Desktop.
Save alexpaul/e8f8857b58f0ee0d0269465807de772c to your computer and use it in GitHub Desktop.
SwiftUI. Animate Button.
import SwiftUI
struct ContentView: View {
@State private var scale: CGFloat = 1
var body: some View {
Button(action: {
withAnimation(.easeIn(duration: 1)) {
self.scale += 20
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
withAnimation(.easeIn(duration: 1)) {
self.scale = 1
}
}
}) {
Image(systemName: "sun.max.fill")
.font(.system(size: 40))
.foregroundColor(Color.yellow)
.scaleEffect(scale)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment