Dev-iOS/SwiftUI

[SwiftUI] Animation 모음 - 좌우로 흔들리는 Animation

lafortune 2024. 9. 10. 07:34
반응형

좌우로 계속해서 흔들리는 Animation 코드

 

Rectangle()
    .frame(width: 100, height: 100)
    .foregroundColor(.blue)
    .offset(x: xOffset)
    .animation(Animation.easeInOut(duration: 0.1).repeatForever(autoreverses: true))
    .onAppear {
        self.xOffset = -10
    }

 

특정 횟수만큼 흔들리도록 하기 위해서는 repeatForever 대신 repeatCount사용.

 

 

 

 

반응형