我的目标是创建一个slotmachine,其中行是一个接一个地旋转,他们需要一个接一个地停止旋转.然而,为了使它看起来不错,行需要至少旋转3秒.我认为PickerView是最好的选择,因为我不知道如何以不同的方式使这项工作.
self.slotMachine.selectRow(99,inComponent: 1,animated: true)
PickerView将进入第99行,但是在1秒内.如何控制第二个(并扩展选择行过程)?一个条件是它应该看起来不错,感觉就像你在玩老虎机.我试过这个:@H_502_3@
UIView.animate(withDuration: 3.0,delay: 0,animations: { () -> Void in self.slotMachine.selectRow(99,animated: true) },completion: nil )
谢谢.@H_502_3@
解决方法
您可以使用计时器并逐个选择单元格,如下所示:
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() } }