【发布时间】:2018-07-25 06:03:35
【问题描述】:
我的问题是我正在使用 Alamofire,我从以下位置添加了 AlamofireActivityIndicator: AlamofireNetworkActivityIndicator GitHub
我的问题是如何将视图添加到该用户所在的 viewController 并进行网络请求,该视图显示指示器而不是在状态栏中显示指示器!
我有一个问题,我将框架代码更改为:
AlamofireNetworkActivityIndicator 框架的原始代码:
private var activityIndicatorState: ActivityIndicatorState = .notActive {
didSet {
switch activityIndicatorState {
case .notActive:
isNetworkActivityIndicatorVisible = false
invalidateStartDelayTimer()
invalidateCompletionDelayTimer()
case .delayingStart:
scheduleStartDelayTimer()
case .active:
invalidateCompletionDelayTimer()
isNetworkActivityIndicatorVisible = true
case .delayingCompletion:
scheduleCompletionDelayTimer()
}
}
}
我已经添加了两个方法来创建和删除屏幕中心 50*50 的红色视图,稍后我将对其进行自定义以显示指示器
fileprivate func myIndicatorView (superView:UIView) {
let view = UIView.init()
view.tag = 2018
view.backgroundColor = .red
superView.addSubview(view)
view.frame = CGRect(x: UIScreen.main.bounds.midX-25,
y: UIScreen.main.bounds.midY-25,
width: 50,
height: 50)
}
fileprivate func removeIndicatorView (superView:UIView) {
superView.subviews.forEach{ (myView) in
if myView.tag == 2018 {
myView.removeFromSuperview()
}
}
}
,但现在我的问题在这里:
private var activityIndicatorState: ActivityIndicatorState = .notActive {
didSet {
switch activityIndicatorState {
case .notActive:
self.myIndicatorView(superView: <#T##UIView#>)
isNetworkActivityIndicatorVisible = false
invalidateStartDelayTimer()
invalidateCompletionDelayTimer()
case .delayingStart:
scheduleStartDelayTimer()
case .active:
self.removeIndicatorView(superView: <#T##UIView#>)
invalidateCompletionDelayTimer()
isNetworkActivityIndicatorVisible = true
case .delayingCompletion:
scheduleCompletionDelayTimer()
}
}
}
问题:
如何定义 ViewControllers 视图而不是 ! ?? ? 这个框架的用法是你在 appDelegate 中输入一行,它会观察每个网络请求:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NetworkActivityIndicatorManager.shared.isEnabled = true
return true
}
【问题讨论】:
-
你基本上想问什么不清楚?
-
@vivekDas 在 [问题:] 部分我问过!如何将任何 ViewControllers 视图添加到 appDelegate 中的自定义类
-
如何将任何 ViewControllers 视图添加到 appDelegate 的自定义类中?你这是什么意思?你想达到什么目标?
-
@vivekDas 我想根据网络请求时间为每个网络请求添加视图!
-
你想显示网络调用的活动指示器视图吗?
标签: ios swift alamofire viewcontroller appdelegate