Created
          August 17, 2024 10:05 
        
      - 
      
 - 
        
Save benigumocom/e220aaf0112c98841a5dba87a33727a9 to your computer and use it in GitHub Desktop.  
    【SwiftUI】Basic animation 👉 https://zenn.dev/maochanz/articles/b3f2b0dcf949c5
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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() | |
| } | 
      
      
  Author
  
  
      
          
      
      
            benigumocom
  
      
      
      commented 
        Aug 17, 2024 
      
    
  

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