我的问题是您看不到 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()
}
延迟将使您看到计时器在旋转。更好的方法是将您的服务层隐藏在协议(protocol)后面,然后您可以拥有一个模拟服务层,该服务层在延迟或出错后返回样本数据。这使您可以测试诸如加载动画和错误处理之类的事情。
关于ios - 当应用程序流畅运行时,您如何测试 UIActivityIndicatorView 是否在旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55763828/