繁体   English   中英

如何检测状态栏 iOS 13 上的触摸

[英]How to detect touch on Status bar 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
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM