I'll provide a simplified example. Let's say when I toggle I want to instantly remove the background of the text without any transition or animation, but have the text itself fade out with opacity. How can I achieve this? Please, do not suggest using a ZStack
instead of .background
; I am looking for a solution in this specific scenario. If it's not possible, please let me know.
struct BackgroundTransition: View { @State var show = true var body: some View { VStack { Group { if show { Text("Some Text") .background( Color.blue .transition(.identity) .animation(.none, value: show) ) } else { Spacer() .frame(maxHeight: .infinity) } } .frame(height: 50) Button("Toggle") { withAnimation { show.toggle() } } } }}
I tried applying .identity
transition to the background view and .none
animation, but it didn't work.