swift (时间器) Timer 的详细使用
// 开启计时器
var timer: Timer?
使用:
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(videoRecordingTotolTime), userInfo: nil, repeats: true)
// 录制时间
@objc private func videoRecordingTotolTime() {
secondCount+=1
// 判断是否录制超时
if secondCount == MaxVideoRecordTime {
timer?.invalidate()
HsuAlert(title: "最常只能录制十分钟呢", message: nil, ensureTitle: "确定", cancleTitle: nil, ensureAction: nil, cancleAction: nil)
}
lethours =secondCount/3600
letmintues = (secondCount%3600) /60
letseconds =secondCount%60
totolTimeLabel.text=String(format:"%02d", hours) +":"+String(format:"%02d", mintues) +":"+String(format:"%02d", seconds)
}
网友评论