我的AppDelegate中有一个AppDelegate方法。我用它来检测状态栏中的抽头。我已经在那里玩了很久了,效果很好。直到iOS 13贝塔出来.
自从使用iOS 13以来,touchesBegan就不再被调用了。在我的应用程序中,与手势相关的其他任何东西都没有改变,在我的AppDelegate中也没有什么改变。除了在touchesBegan 12中调用touchesBegan而在iOS 13中调用之外,我没有什么可做的。
但到目前为止没有运气,所以我在这里分享这一点,以防其他人有同样的或类似的问题。
更新:1我发现了以下问题,它们是半相关的,让我看到了苹果在iOS 13中的新产品iOS 13。这些问题都没有解释为什么touchesBegan没有被调用。到目前为止,我还没有理解UISceneDelegate,还没有找到为什么没有调用touchesBegan。
发布于 2020-02-14 04:49:32
这就是我正在做的事情,也许不是很好,但到目前为止只有工作解决方案。很高兴得到改进。
这也适用于SceneDelegate。
ScrollToTopViewController.swift
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函数。
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)
}发布于 2019-10-16 03:09:13
我最近也有同样的问题。我花了几个小时才弄明白。我在主窗口上创建了另一个UIWindow,以显示应用程序通知/警报。由于某种原因,当使用ios 13时,它会吃掉所有的触摸操作。我的解决办法是在顶部禁用用户交互。但这意味着您显然不能与通知/警报进行任何用户交互。
https://stackoverflow.com/questions/57806710
复制相似问题