ios - Alamofire 的加载旋转器

标签 ios json swift3 alamofire

在我的应用程序中,我使用 alamofire 将 Web api 中的 JSON 数据解析到我的应用程序中。我想在加载数据时添加一个加载微调器。我看过:

Alamofire Loading Indicator

但这只显示了上面的小网络图标。任何帮助都会很棒。

最佳答案

您正在寻找事件指示器 View UIActivityIndi​​catorView。这必须手动添加。您可以通过 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/

相关文章:

ios - 在 Swift 中使用 PFQueryTableViewController(来自解析)

具有用户位置和适当比例/跨度的 iOS init MKMapView

java - Flex JSON 无法正确序列化/反序列化 LinkedHashMap

ios - 如何相对于父 View 的边距将 AddConstraint 添加到按钮,使其看起来距上边距 30 度,距右边距 30 度

ios - 必须调用父类(super class) 'UICollectionView' 的指定初始化程序

iOS tableview 如何检查它是向上还是向下滚动

ios - 在第一个 Controller 发生事件时以编程方式返回到第一个 Controller

javascript - Json服务器错误: Data must be an object.需要将JSON数组更改为JSON对象

javascript - Backbone.js:从集合构建 JSON 数组

ios - 获取事件的 MSConversation 以将消息发送到