【问题标题】:How to detect status bar taps in iOS13?如何在 iOS13 中检测状态栏点击?
【发布时间】:2023-03-12 22:42:01
【问题描述】:

我之前用过下面的代码,在iOS12上运行得非常好:

    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) {
            NotificationCenter.default.post(statusBarTappedNotification)
        }
}

但它不再适用于 iOS13。有什么想法吗?

【问题讨论】:

  • 好的,看起来这是我迄今为止在 iOS13 中找到的唯一工作方式来添加一个虚拟 UIScrollView... 不是最优雅的解决方案,但它至少可以工作:self.dummyScrollview.frame = self.view.frame self.dummyScrollview.contentSize.height = self.view.frame.height + 1 self.dummyScrollview.contentOffset.y = 1 dummyScrollview.delegate = self self.view.addSubview(dummyScrollview) func scrollViewShouldScrollToTop(_ scrollView : UIScrollView) -> Bool { //DO WHATEVER YOU NEED TO ON ON STATUS BAR TAP HERE return false }
  • 这是一个在 iOS 13 中仍然有效的解决方案:stackoverflow.com/a/3753976/9087914

标签: swift status ios13


【解决方案1】:

我已经能够检测到带有 UIStatusBarManager 的 Objective-C 类别的水龙头。我认为这不可能作为快速扩展或其他快速方式。

@implementation UIStatusBarManager (CAPHandleTapAction)
-(void)handleTapAction:(id)arg1 {
    // Your code here
}
@end

【讨论】:

  • 这似乎是一个很好的解决方案,但它似乎禁用了滚动到顶部的行为,有没有办法在使用它的同时恢复它?
  • 是的,但它涉及到 swizzling github.com/ionic-team/capacitor/blob/…
猜你喜欢
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2018-12-18
  • 2019-12-19
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 2011-03-26
相关资源
最近更新 更多