NumberScrollAnimatedView 0.2.1

NumberScrollAnimatedView 0.2.1

Alex Smetannikov 维护。



  • 作者
  • Alexander Smetannikov

Cocoapods Platform Language License: MIT

NumberScrollAnimatedView

该组件可在每个数字符号上显示带有滚动动画的字符串。滚动方向、动画持续时间和时间偏移量可以轻松自定义。

支持 Swift 3、Swift 4 和 Swift 4.2。

All random

安装

CocoaPods

CocoaPods 是向您的项目添加 NumberScrollAnimatedView 的首选方式。

只需将以下行添加到您的 Podfile 中

pod 'NumberScrollAnimatedView'

然后,在终端中运行 pod install

之后,您可以通过以下方式将 NumberScrollAnimatedView 包含在您需要的任何地方

import NumberScrollAnimatedView

手动

如果您不想使用依赖关系管理器,您可以将 NumberScrollAnimatedView 手动添加到项目中。

您可以通过将包含 "NumberScrollAnimatedView" 文件夹以及 "NumberScrollableColumn.swift" 和 "NumberScrollAnimatedView.swift" 两个文件的文件夹复制到项目中来实现。

使用方法

let animatedView = NumberScrollAnimatedView()

// Add to superview, configure view constraints etc...

// Customize a view properties like background color, font size and color
animatedView.backgroundColor = UIColor(red: 255/255, green: 47/255, blue: 146/255, alpha: 1)
animatedView.font = UIFont.boldSystemFont(ofSize: 64)
animatedView.textColor = .white

// Set animation properties
animatedView.animationDuration = 5
animatedView.scrollingDirectionRule = { (_, columnIndex) in return (columnIndex % 2) == 0 ? .down : .up }

// Set a value which will be displayed
animatedView.text = "220-548"

// Start animation
animatedView.startAnimation()

动画参数

  • 动画持续时间
  • animationTimeOffsetRule,指定每个数字符号的动画开始时间偏移量。默认情况下,该函数返回0到1之间的随机值。
  • animationDurationOffsetRule,指定每个数字符号的动画持续时间变化。默认情况下,该函数返回0到1之间的随机值。
  • scrollingDirectionRule,指定每个数字符号的动画方向(向上或向下)。默认情况下,此规则返回随机值。
  • inverseSequenceRule,指定是否反转数字序列。默认序列为0123456789,反转后为9876543210

动画示例

  1. 默认情况下,所有动画参数都是随机的。

All random

  1. 滚动方向向下。
animatedView.scrollingDirectionRule = { (_, _) in return .down }

Scrolling direction is down

  1. 滚动方向向上,序列未反转,所有列的动画持续时间相同。
animatedView.scrollingDirectionRule = { (_, _) in return .up }
animatedView.inverseSequenceRule = { (_, _) in return false }
animatedView.animationDurationOffsetRule = { (_, _) in return 0 }

Scrolling direction is up, sequence don't inverted,  animation duration the same for all columns

作者

由亚历山大·斯梅塔尼科夫([email protected])创建