My animateExample() func works because the image and the 2 texts are updated twice but I can't make it "nice" with an animation. For a reason I don't know, withAnimation(.easeInOut) does nothing. I just want a simple fade animation and not only a brutal change of the image and texts.
What's wrong with my current code?
struct ExampleView: View { @State private var isAnimated = true private let date = Date() var body: some View { HStack { ZStack { Circle() .onAppear { animateExample() } Image(isAnimated ? "city" : "sedan") } VStack { Text(isAnimated ? "Renault Clio" : "Audi A8") Text(isAnimated ? "City - \(date, format: .dateTime.day(.twoDigits).month(.twoDigits))" : "Sedan - \(date, format: .dateTime.day(.twoDigits).month(.twoDigits))") } } } func animateExample() { withAnimation(.easeInOut) { DispatchQueue.main.asyncAfter(deadline: .now() + 2) { isAnimated = false DispatchQueue.main.asyncAfter(deadline: .now() + 2) { isAnimated = true } } } } } Bonus question: nothing to see with what I want to achieve but is there a possibility to not repeat the date in the second text?
Thanks in advance!
ToolbarItem.ToolbarItemin your question. Please edit it to show a minimal reproducible example, of how the linked question does not answer your question.toolbar()because there's no reason. What I want to achieve and my toolbar aren't linked but for an obscure reason with the solution from your link, one of myToolbarItemis "offseted" during the animation. It's quite funny!.animation(.easeInOut(duration: 1), value: isAnimated)repeated 3 times as I can't reduce them with just one line of code withwithAnimation(). Thanks anyway!