如何防止在滚动UIPickerView时暂停计时器?

时间:2019-03-27 16:55:12

标签: swift timer uilabel uipickerview

我按照以下步骤重现此问题。滚动UIPickerView时,计时器暂停。我该如何预防?

我在班级中设置了计时器:

var testTimer:Timer = Timer()

在此示例中,我在viewDidLoad中定义了计时器:

testTimer = Timer.scheduledTimer(timeInterval: 0.10, target: self, selector: #selector(self.testFunction), userInfo: nil, repeats: true)

定时器功能。滚动UIPickerView时,该行不打印:

@objc func testFunction(){
    print("testFunction called")
}

这是每次滚动UIPickerView时调用的函数。根据{{​​3}}的有关使用UIPickerView重用视图的说法,这是不可能的,并且文档是错误的,因此我不在此处进行检查:

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

    let customWidth = 300
    let customHeight = 300

    let label = UILabel(frame:CGRect(x:0, y:0, width:customWidth, height:customHeight))

    label.text = "\(row)"

    label.textColor = UIColor.black
    label.font = UIFont(name:"HelveticaNeue-Bold", size: 18.0)
    label.textAlignment = .center

    return label

}

0 个答案:

没有答案