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()
    }
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...