ios - 如何检测状态栏 iOS 13 上的触摸
问题描述
我在状态栏框架的 AppDelegate keyWindow 中添加了一个自定义视图。在 iOS 13 之前,touchbegan被调用,使用它来比较触摸位置和状态栏坐标。
我进行了很多搜索,但找不到任何为什么 touchbegain 停止被调用的原因。
我还尝试通过在 iOS 13 中隐藏状态栏而不是添加状态栏框架的子视图,这样 touchbegan 被调用,但是当我隐藏状态栏时视图正在上升。
如果有人对此有任何解决方案,请发布您的回复。
解决方案
尝试在 AppDelegate.swift 中使用此代码
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let statusBarRect = UIApplication.shared.statusBarFrame
guard let touchPoint = event?.allTouches?.first?.location(in: self.window) else { return }
if statusBarRect.contains(touchPoint) {
// tap on statusbar, do something
}
}
推荐阅读
- python - 为什么所有列表都获得相同的值 - python?
- reactjs - 在 Formik React 表单的 handleSubmit 方法中设置 Redux State
- asp.net - 访问 HTTPS Web 服务时出现 403 错误(restful)
- ruby-on-rails - 检查触发特定 Job id 的工作人员名称
- java - Spring服务空指针异常
- angular - 我想发送一个可观察的 2 个父组件。我该怎么做?我需要使用 EventEmitter 吗?
- python - ModuleNotFoundError:没有名为 celery 的模块
- python - 使用变量作为参数
- apache-camel - 如何使用 Camel toD 和 netty4-http 组件?动态url优化问题
- node.js - 编辑用户数据后如何更新passportJWT数据?