1

I found this article regarding the same problem as I have:

Spinner animation starts bouncing once the view is updated

However, the best solution given does not appear to work in my case. It could well be I have missed something in the solution, but I cannot see anything!

struct OscillatingTextView: View 
{
@State var doAnimation = false
var text: String

var animation: Animation {
        Animation.easeInOut(duration: 1.0)
            .repeatForever(autoreverses: true)
    }

var body: some View {
    HStack{
    ForEach(Array(text), id: \.self)
        {   letter in
            Text(String(letter))
                .rotationEffect(Angle.degrees(doAnimation ? 30:-30))
                .animation(doAnimation ? animation : .default, value: doAnimation) //as advised in Asperi solution
        }
        .font(.largeTitle)
    }
    .onAppear()
    {
        doAnimation.toggle()
    }
}
}
HillInHarwich
  • 441
  • 6
  • 25
  • 1
    Do you use it in NavigationView? If yes, then you need this https://stackoverflow.com/a/64566746/12299030. Btw, as standalone your view works fine here: Xcode 13 / iOS 15. – Asperi Dec 09 '21 at 12:04
  • This solved it! Thank you! Is there a reason for this behaviour? – HillInHarwich Dec 09 '21 at 12:11

0 Answers0