import SwiftUIstruct SwiftUIAnimationIntro: View { @State private var flag = false var body: some View { VStack { RoundedRectangle(cornerRadius: 20) .foregroundColor(.orange) .frame(width: 200, height: 200) .offset(x: 0, y: flag ? 400 : 0) Spacer() Button("Animate") { flag.toggle() } } .font(.title) } }
struct SwiftUIAnimationIntro: View { @State private var flag = false var body: some View { VStack { RoundedRectangle(cornerRadius: 20) .foregroundColor(.orange) .frame(width: 200, height: 200) .offset(x: 0, y: flag ? 400 : 0) Spacer() Button("Animate") { flag.toggle() } } .animation(Animation.easeInOut, value: flag) .font(.title) } }
With that we have reached the end of this article. Thank you once again for reading. Subscribe to our weekly newsletter at https://www.devtechie.com