ios – 如何降低PickerView中选择行的速度?

我的目标是创建一个slotmachine,其中行是一个接一个地旋转,他们需要一个接一个地停止旋转.然而,为了使它看起来不错,行需要至少旋转3秒.我认为PickerView是最好的选择,因为我不知道如何以不同的方式使这项工作.

这是我的代码:

self.slotMachine.selectRow(99,inComponent: 1,animated: true)

PickerView将进入第99行,但是在1秒内.如何控制第二个(并扩展选择行过程)?一个条件是它应该看起来不错,感觉就像你在玩老虎机.我试过这个:

UIView.animate(withDuration: 3.0,delay: 0,animations: { () -> Void in
        self.slotMachine.selectRow(99,animated: true)
    },completion: nil )

但这没效果.

谢谢.

解决方法

您可以使用计时器并逐个选择单元格,如下所示:
var timer = Timer()
var currentRow = 0

override func viewDidLoad() {
    super.viewDidLoad()
    timer = Timer.scheduledTimer(timeInterval: 0.2,target: self,selector: #selector(timerAction),userInfo: nil,repeats: true)
}

func timerAction() {
    currentRow += 1
    self.slotMachine.selectRow(currentRow,animated: true)
    if(currentRow == 99){
        timer.invalidate()
    }
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...