Swiftui transition with related animation not working

code is simple, when I use .opacity transition it all works well, but when I switch to .offset(x: 100, y: 100), it won't animate, I'm wondering why, anyone can help?

import SwiftUI

struct ContentView: View {
    @State private var show = false
    
    var body: some View {
        VStack {
            Spacer()
            
            if show {
                Text("AAAA")
                    .transition(
                        AnyTransition
                            //                            .offset(x: 100, y: 100)
                            .opacity
                            .animation(
                                Animation
                                    .easeInOut(duration: 1)
                                    .delay(5)
                        )
                )
            }
            
            Spacer()
            
            Button("Click") {
                self.show.toggle()
            }
            .padding()
        }
    }
}

Same issue, but as a possible workaround wrapping the calls that trigger the transition in withAnimation does trigger the animation correctly even when using .offset.

1 Like
Terms of Service

Privacy Policy

Cookie Policy