Home > Net >  SwiftUI tvOS button animation - how to stop y axis movement
SwiftUI tvOS button animation - how to stop y axis movement

Time:09-17

this simple code of x offset animation causes a text to move also on y axis when the text is part of a button (on tvOS 14.7)

struct Animate: View
{
    @State var scrollText: Bool = false
    
    var body: some View {
        Button(action: {}, label: {
            Text("This is My Text !")
                .offset(x: scrollText ? 0 : 200, y: 0)
                .animation(Animation.linear(duration: 1).repeatForever(autoreverses: true))
                .onAppear {
                  self.scrollText.toggle()
                }
        })
    }
}

see the animation behavior here: No weird position animation

This video might also be helpful

  • Related