I have the steps below to reproduce this issue. As I scroll a UIPickerView, my timers pause. How do I prevent this?
I setup my timer within my class:
var testTimer:Timer = Timer()
In this example I define the timer in viewDidLoad:
testTimer = Timer.scheduledTimer(timeInterval: 0.10, target: self, selector: #selector(self.testFunction), userInfo: nil, repeats: true)
Timer function. The line does not print as UIPickerView is scrolled:
@objc func testFunction(){
print("testFunction called")
}
This is the function that's called every time UIPickerView is scrolled. According to a previous answer about reusing views with UIPickerView, it is not possible, and the documents are wrong, so I'm not checking for that here:
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
}