首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >touchesBegan在iOS 12中被调用,但在iOS 13中没有被调用

touchesBegan在iOS 12中被调用,但在iOS 13中没有被调用
EN

Stack Overflow用户
提问于 2019-09-05 13:33:45
回答 2查看 2.1K关注 0票数 11

我的AppDelegate中有一个AppDelegate方法。我用它来检测状态栏中的抽头。我已经在那里玩了很久了,效果很好。直到iOS 13贝塔出来.

自从使用iOS 13以来,touchesBegan就不再被调用了。在我的应用程序中,与手势相关的其他任何东西都没有改变,在我的AppDelegate中也没有什么改变。除了在touchesBegan 12中调用touchesBegan而在iOS 13中调用之外,我没有什么可做的。

但到目前为止没有运气,所以我在这里分享这一点,以防其他人有同样的或类似的问题。

更新:1我发现了以下问题,它们是半相关的,让我看到了苹果在iOS 13中的新产品iOS 13。这些问题都没有解释为什么touchesBegan没有被调用。到目前为止,我还没有理解UISceneDelegate,还没有找到为什么没有调用touchesBegan

视图控制器响应iOS 12中的应用程序委托通知,但在iOS 13中没有响应。

如何检测状态栏中的触摸

iOS13:如何检测状态栏单击事件?

EN

回答 2

Stack Overflow用户

发布于 2020-02-14 04:49:32

这就是我正在做的事情,也许不是很好,但到目前为止只有工作解决方案。很高兴得到改进。

  • 创建内容大于其框架的TableViewController。
  • 在视图中,滚动到表视图的末尾。
  • 设置TableViewController的框架与StatusBarFrame相同,并将其添加到窗口的根视图控制器
  • 在scrollViewShouldScrollToTop内部处理ScrollToTop事件并滚动到末尾以获取下一个事件。
  • 在StatusBar帧更改中,更新TableViewController的框架。

这也适用于SceneDelegate。

ScrollToTopViewController.swift

代码语言:javascript
复制
class ScrollToTopViewController: UITableViewController {

    private let numberOfRow = 2
    private let cellIdentifier = "empty"

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.allowsSelection = false
        tableView.separatorColor = .clear
        tableView.backgroundColor = .clear
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellIdentifier)
        view.autoresizingMask = []
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        scrollToBottom()
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return view.frame.size.height
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return numberOfRow
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) ?? UITableViewCell()
        cell.backgroundColor = .clear
        return cell
    }

    override func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            self.scrollToBottom()
        }
        print("HANDLE SCROLL TO TOP")
        return true
    }

    private func scrollToBottom() {
        tableView.scrollToRow(at: IndexPath(row: numberOfRow - 1, section: 0), at: .bottom, animated: false)
    }
}

AppDelegate.swift或等效的SceneDelegate函数。

代码语言:javascript
复制
private let scrollToTopVC = ScrollToTopViewController()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    NotificationCenter.default.addObserver(self,
                                           selector: #selector(updateScrollToTopVC),
                                           name: UIApplication.didChangeStatusBarFrameNotification,
                                           object: nil)
    return true
}

func applicationDidBecomeActive(_ application: UIApplication) {
    updateScrollToTopVC()
}

@objc
private func updateScrollToTopVC() {
    guard let viewController = window?.rootViewController else {
        return
    }
    let statusBarFrame: CGRect

    if #available(iOS 13.0, *) {
        statusBarFrame = UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?? .zero
    } else {
        statusBarFrame = UIApplication.shared.statusBarFrame
    }
    scrollToTopVC.view.frame = statusBarFrame
    viewController.addChild(scrollToTopVC)
    viewController.view.addSubview(scrollToTopVC.view)
    scrollToTopVC.didMove(toParent: viewController)
}
票数 1
EN

Stack Overflow用户

发布于 2019-10-16 03:09:13

我最近也有同样的问题。我花了几个小时才弄明白。我在主窗口上创建了另一个UIWindow,以显示应用程序通知/警报。由于某种原因,当使用ios 13时,它会吃掉所有的触摸操作。我的解决办法是在顶部禁用用户交互。但这意味着您显然不能与通知/警报进行任何用户交互。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57806710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档