我在我的ViewController willAppear方法中进行了一个API调用,在API响应完成之前,我使用这个showWait和hideWait方法来显示和关闭活动指示器。但问题是,在我的ViewController中,我有一个带有不同自定义单元格的表视图,假设我在加载过程中不断点击这些单元格,一旦加载消失,它的所有操作都会被多次调用。下面是我用于显示和隐藏指示器的代码,我尝试将userInteractionEnabled设置为false,但不起作用。此外,尝试了beginIgnoringInteractionEvents,它在一定程度上工作,但如果你继续点击,直到加载程序消失,这也失败了。不确定如何从这里继续。任何帮助都是非常感谢的。
class func showWait() {
DispatchQueue.main.async {
UIApplication.shared.beginIgnoringInteractionEvents()
if let appdelegate = UIApplication.shared.delegate as? AppDelegate,
appdelegate.myIndicatorView == nil {
appdelegate.myIndicatorView = MyIndicatorView(frame: UIScreen.main.bounds)
appdelegate.window?.subviews[0].addSubview(appdelegate.myIndicatorView!)
}
}
}
class func hideWait() {
if let appdelegate = UIApplication.shared.delegate as? AppDelegate,
appdelegate.myIndicatorView != nil {
DispatchQueue.main.async {
appdelegate.myIndicatorView?.removeFromSuperview()
appdelegate.myIndicatorView = nil
UIApplication.shared.endIgnoringInteractionEvents()
}
}
}
发布于 2019-11-29 16:13:54
替换:UIApplication.shared.beginIgnoringInteractionEvents()
->>> self.view.isUserInteractionEnabled = false
和
UIApplication.shared.endIgnoringInteractionEvents()
->>> self.view.isUserInteractionEnabled = true
发布于 2019-09-15 14:31:37
begin/end IgnoringInteractionEvents
在iOS 13.0中已被弃用,请在您的"myIndicatorView“上使用UIView的userInteractionEnabled
属性。并使您的"myIndicatorView全屏,以便它覆盖整个屏幕,这将允许您阻止整个应用程序,而它是可见的。
发布于 2019-11-27 08:39:18
iOS 13.0中现在不推荐使用IgnoringInteractionEvents,因此必须使用isUserInteractionEnabled
DispatchQueue.main.async {
appdelegate.myIndicatorView?.removeFromSuperview()
appdelegate.myIndicatorView = nil
//you must use this
self.view.isUserInteractionEnabled = false
//This is deprecated in iOS13
// UIApplication.shared.endIgnoringInteractionEvents()
}
https://stackoverflow.com/questions/57944272
复制相似问题