ios - 自定义 NavigationBarButton 在 iOS 12 及更低版本上没有控制器,iOS 13 正在运行
问题描述
我正在尝试使用带有自己的 ViewController 的 CustomView 作为正确的 NavigationBar(barbuttonitem)。此视图需要根据应用状态进行更新。视图是这样实现的:
private func addUploadStatusToNavigationController() {
cloudView = UploadStatusViewController<UploadStatusNavigationView>()
let tgr = UITapGestureRecognizer(target: self, action: #selector(cloudViewTapped))
cloudView.customView.addGestureRecognizer(tgr)
let cloudViewButton = UIBarButtonItem(customView: cloudView.customView)
self.navigationItem.rightBarButtonItem = cloudViewButton
cloudView.setStatus(status: uploadStatusService.getStatus())
if let btn = self.navigationItem.rightBarButtonItem?.customView {
btn.frame = CGRect(x: 0, y: 0, width: (self.navigationController?.navigationBar.frame.width ?? 0) * 0.6, height: 44)
}
uploadStatusService.delegate = self
}
此方法在 viewWillAppear 中调用。
在我通过点击视图选项卡打开警报之前,iOS 13 一切正常。如果我再次关闭它,视图会丢失它自己的控制器 - UploadStatusViewController -(至少在 ViewDebugger 中)。通过此控制器运行的状态更新仍然可以正常工作。水龙头不再被识别。
在 iOS 12 中,没有检测到轻按,甚至第一次也没检测到。
显示警报如下所示:
private func askUserToStop() {
let alert = UIAlertController(title: "OneDrive", message: "BackupPopup.Cancel.Message".localized, preferredStyle: .alert)
let action1 = UIAlertAction(title: "Button_Title_Cancel".localized, style: .cancel, handler: nil)
alert.addAction(action1)
self.present(alert, animated: true, completion: nil)
}
如果我将一个新控制器推到 NavigationStack 上并再次导航回来,则 GestureRecognizer 只能再次工作(iOS13)。我实际上希望 TapGestureRecognizer 能够在弹出窗口出现之后保留下来,并且也可以在 iOS 12 下工作。
恐怕我不知道还能尝试什么。
编辑:
总结:
iOS 12:点击时无操作,ViewDebugger 中的视图后面没有 UploadStatusViewController
iOS 13:第一次点击时动作,UploadStatusViewController 在第一次点击后在 ViewDebugger 中被删除。
iOS 12 和 13:UploadStatusViewController 的其他操作,例如更新它的 customView 工作正常。
解决方案
推荐阅读
- ruby - 用于传递块的 Ruby 语法
- android - Android Dagger2 依赖周期错误?为什么
- google-api - 如何获取 googleapi-nodejs-client 的正确参数
- java - Docx4j:在从 docx 生成的 html 中嵌入图像
- security - 如何在 Symfony 4 中配置 http_basic 防火墙以在身份验证失败时在响应正文中返回 JSON?
- python - 如何正确将 tflite_graph.pb 转换为 detect.tflite
- javascript - 正则表达式 | 应用函数式编程将字符串转换为 URL Slug
- java - JAVA中根据方法和类访问自定义注解字段
- ios - 从邮件客户端打开已安装的 PWA
- python - 如何让我的输入选择单词而不是字母?(Python)