Numbers not animating when used in UIKit
rubnov opened this issue · comments
First off, thank you for this repo!
I'm trying to embed MovingNumbersView
in UIKit using UIHostingControlller
. However, the numbers are not animating as shown in your README video snippets. Here is my code excerpt:
let randomInt = Double.random(in: 0..<10000000)
let value : Double = PSUnitConversion.localizedDistance(fromMeters: randomInt)
let vc = UIHostingController(rootView: MovingNumbersView(number: value, numberOfDecimalPlaces: 1) { str in
Text(str).font(.largeTitle)
})
if let subview = vc.view {
subview.translatesAutoresizingMaskIntoConstraints = false
addChild(vc)
view.addSubview(subview)
NSLayoutConstraint.activate([
subview.centerXAnchor.constraint(equalTo: view.centerXAnchor),
subview.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
vc.didMove(toParent: self)
}
The MovingNumbersView
appears on the screen, but the numbers are not animating.
I also couldn't find any way to "update" the MovingNumbersView, i.e. to animate from one set of numbers to another. Can this be done?
Finally, is there an example project that shows how to use MovingNumbersView
within UIKit?
thank you for your help!