How would it be possible to animate Text
or TextField
views from Swift UI?
By animation I mean, that when the text changes it will "count up".
For example given some label, how can an animation be created that when I set the labels text to "100" it goes up from 0 to 100. I know this was possible in UIKit using layers and CAAnimations, but using the .animation()
function in Swift UI and changing the text of a Text
or TextField
does not seem to do anything in terms of animation.
I've taken a look at Animatable
protocol and its related animatableData
property but it doesn't seem like Text
nor TextField
conform to this. I'm trying to create a label that counts up, so given some value, say a Double
the changes to that value would be tracked, either using @State
or @Binding
and then the Text
or TextField
would animate its content (the actual string text) from what the value was at to what it was set to.
Edit:
To make it clearer, I'd like to recreate a label that looks like this when animated: