在我的应用程序中,我使用 alamofire 将 Web api 中的 JSON 数据解析到我的应用程序中。我想在加载数据时添加一个加载微调器。我看过:
但这只显示了上面的小网络图标。任何帮助都会很棒。
最佳答案
您正在寻找事件指示器 View UIActivityIndicatorView
。这必须手动添加。您可以通过 Storyboard添加它并启用 hidesWhenStopped
,以便指示器在停止时不可见。
无论如何,您都必须在启动请求之前手动调用 startAnimating
,然后在请求完成时手动调用 stopAnimating
。
要以编程方式完成这一切,它看起来像这样:
// Assuming in the view controller
let activityIndicator = UIActivityIndicatorView(style: .gray) // Create the activity indicator
view.addSubview(activityIndicator) // add it as a subview
activityIndicator.center = CGPoint(x: view.frame.size.width*0.5, y: view.frame.size.height*0.5) // put in the middle
activityIndicator.startAnimating() // Start animating
request.perform { data, error in
activityIndicator.stopAnimating() // On response stop animating
activityIndicator.removeFromSuperview() // remove the view
// ... process data
}
关于ios - Alamofire 的加载旋转器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40677496/