Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Created August 17, 2024 10:05
Show Gist options
  • Save benigumocom/e220aaf0112c98841a5dba87a33727a9 to your computer and use it in GitHub Desktop.
Save benigumocom/e220aaf0112c98841a5dba87a33727a9 to your computer and use it in GitHub Desktop.
【SwiftUI】Basic animation 👉 https://zenn.dev/maochanz/articles/b3f2b0dcf949c5
import SwiftUI
struct TextAnimationView: View {
@State private var scale = false
@State private var rotation = false
@State private var opacity = false
@State private var offset = false
var body: some View {
VStack {
Image(systemName: "face.smiling")
.font(.system(size: 100))
.scaleEffect(scale ? 2 : 1)
.animation(.default, value: scale)
.rotationEffect(.degrees(rotation ? 0 : 360))
.animation(.easeIn, value: rotation)
.opacity(opacity ? 0.2 : 1)
.animation(.easeOut, value: opacity)
.offset(CGSize(width: offset ? 50 : 0, height: offset ? 50 : 0))
.animation(.spring(duration: 0.5, bounce: 0.5), value: offset)
Button("scale") {
scale.toggle()
}
Button("rotation") {
rotation.toggle()
}
Button("opacity") {
opacity.toggle()
}
Button("offset") {
offset.toggle()
}
}
.buttonStyle(.borderedProminent)
}
}
#Preview {
TextAnimationView()
.padding()
}
@benigumocom
Copy link
Author

sc 2024-08-16 at 12 08 50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment