ios - UIprogressView(progerssView)动画未重新启动
问题描述
我正在玩耍以学习和实现一个progressView
使用函数触发的函数,并在单击按钮时使用另一个函数重置(并为其提供值)。出于某种原因,在第一次点击后,即使在随后的点击中也调用了函数并且progressView
重置,它的动画没有重新启动(使用 print() 检查的函数和值都是正确的......)
import UIKit
class ViewController: UIViewController {
let eggTimes = ["Soft" : 5, "Medium" : 7, "Hard": 12]
@IBOutlet weak var progressView: UIProgressView!
//reset the progress bar
func resetProgress(){
progressView.setProgress(0, animated: true)
print("function progress view reset fired")
}
//starts the prgress bar
func startProgressView(duration: Double) {
UIView.animate(withDuration: duration) {
print("progress bar has been initiated")
self.progressView.setProgress(1.0, animated: true)
}
}
@IBAction func hardnessSelected(_ sender: UIButton) {
resetProgress()
print("progress bar has been reset")
let hardness = sender.currentTitle!
var timerCounter = eggTimes[hardness]! * 10
let temp1: Double = Double(timerCounter)
print("temp 1 = \(temp1) ")
self.startProgressView(duration: temp1)
print(eggTimes[hardness]!)
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { (timer) in
if timerCounter > 0 {
timerCounter -= 1
// print(timerCounter)
}
else {
print("egg ready")
timer.invalidate()
}
}
}
}
解决方案
推荐阅读
- string - [MASM32, irvine32 library]将空格分隔的BYTE字符串转换为整数,我做对了吗?
- javascript - 如何在 jsTree 中创建根节点(版本 3.2.1)
- google-sheets - 查询选择器,比较日期的 Where 子句
- swiftui - CoreData 一对多关系的 SwiftUI 视图管理
- python - 使用 Cx-Freeze 编译 python 项目
- android - 从适配器访问数据库 (Kotlin)
- python - 在 Python 中用“输入”调用“def”
- performance - 在页面期间,如何显示屏幕截图以避免 SPEED INDEX 错误?
- firebase - 如何使用颤振流从 Firestore 获取数据
- c - 混淆比较结构