我的问题是你看不到UIActivityIndicatorView
,因为应用程序运行顺利,所以我不确定代码是否正确。
以下是提到它的一切:
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet var progressBar: UIView!
@IBOutlet weak var progressLabel: UILabel!
@IBOutlet weak var loadingIndicator: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
loadingIndicator.hidesWhenStopped.toggle()
nextQuestion()
}
func startOver() {
loadingIndicator.startAnimating()
questionNumber = 0
score = 0
nextQuestion()
}
func nextQuestion() {
updateUI()
loadingIndicator.stopAnimating()
if questionNumber <= 12 {
func updateUI() {
scoreLabel.text = "Score: \(score)"
progressBar.frame.size.width = (view.frame.size.width / 13) * CGFloat(questionNumber)
}
这不是代码,而不是全部。
您可以使用以下任一方法人为地向nextQuestion()
添加延迟:
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { [weak self] _ in
self?.nextQuestion()
}
要么
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.nextQuestion()
}
延迟将允许您看到计时器旋转。更好的方法是将服务层隐藏在协议后面,然后您可以拥有一个模拟服务层,在延迟或错误输出后返回样本数据。这使您可以测试加载动画以及错误处理等内容。
只是为了检查它是否正常工作你可以使用breakpoint one activityindicator开始动画的行你也可以使用timer
Timer.scheduledTimer(withTimeInterval: 5, repeat: false){ (timer) in
//start animating here
}