ios - 快速加载时禁用用户交互
问题描述
我在 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()
}
}
}
解决方案
替换:UIApplication.shared.beginIgnoringInteractionEvents()
->>>self.view.isUserInteractionEnabled = false
和
UIApplication.shared.endIgnoringInteractionEvents()
->>>self.view.isUserInteractionEnabled = true
推荐阅读
- android-layout - 无法在 android 中正确查看 UI
- containers - 为什么在同一端口上运行不同的 Docker 映像实例
- python-3.x - 如何包装 PyTorch 函数并实现 autograd?
- linkedin - 是否可以使用 Linkedin Api 安排帖子
- javascript - 无法通过本机反应连接到 aws iot 设备
- c# - 如何在 Windows 窗体 c# 的 RDLC 报告中显示二进制图像
- android - 使用表单数据改造发布请求
- react-native-android - 在 react-native-maps 中按下标记时如何在 MapView 之外显示文本
- xcode - 找不到以下错误的解决方案
- elixir - 如何在预加载中聚合