ScrollCounter
安装
ScrollCounter可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'ScrollCounter'
使用
ScrollCounter是一个在数字间转换时实现美观滚动动画的框架。此框架模仿了Robinhood应用中看到的动画。
查看这篇Medium文章,了解ScrollCounter是如何工作的。
单个数字一个带有单个数字的滚动计数器可以用两行代码创建和动画化
// Initialize a scrolling counter for the standard range between 0-9 (other ranges can be used as well).
let singleDigit = DigitScrollCounter(font: UIFont(name: "Avenir-Black", size: 150)!, textColor: .white, backgroundColor: .black, scrollDuration: 0.3, gradientColor: .black, gradientStop: 0.2)
// Scrolls to the item at the 8th index. For a DigitScrollCounter, this means scroll to the number 8.
singleDigit.scrollToItem(atIndex: 8)
无界数字使用`NumberScrollCounter`处理一个无界范围的数字
// Initialize a number counter, which is a view composed of `DigitScrollCounter`s.
let numberCounter = NumberScrollCounter(value: 1, scrollDuration: 0.33, decimalPlaces: 2, prefix: "$", suffix: "", font: font.withSize(40), textColor: .white, gradientColor: .black, gradientStop: 0.2)
// Set a new value. This will trigger the animation to show the given value.
numberCounter.setValue(123.45)