Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 4 characters in body
Source Link
Umair M
  • 10.8k
  • 6
  • 45
  • 76

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I amhave a very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I am very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I have a very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)

fixed code
Source Link
Umair M
  • 10.8k
  • 6
  • 45
  • 76

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) // .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I am very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) // .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I am very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I am very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)

Source Link
Umair M
  • 10.8k
  • 6
  • 45
  • 76

How to animate/transition text value change in SwiftUI

I am trying to animate value change in a text using withAnimation but it doesn't seem to work. I have come across a similar question but the answer is not animating the text value.

I am trying to recreate this behaviour in pure SwiftUI (UIKit Example):

enter image description here

I have tried this code but it doesn't animate the text change:

struct TextAnimationView: View { @State private var textValue = "0" var body: some View { VStack (spacing: 50) { Text(textValue) .font(.largeTitle) .frame(width: 200, height: 200) // .transition(.opacity) Button("Next") { withAnimation (.easeInOut(duration: 1)) { self.textValue = "\(Int.random(in: 1...100))" } } } } } 

I am very little experience with SwiftUI, is there another way to achieve this?

Thanks in advance :)