[英]touchesBegan is called in iOS 12 but is not called in iOS 13
我的AppDelegate
有一個touchesBegan
方法。 我用它來檢測狀態欄中的點擊。 我已經在那里使用了很長時間,而且效果很好。 直到 iOS 13 測試版出來......
自從使用 iOS 13 以來, touchesBegan
就不再被調用了。 我的應用程序中與手勢相關的任何其他內容都沒有改變,我的AppDelegate
沒有任何改變。 除了在 iOS 12 而不是在 iOS 13 中調用touchesBegan
之外,我真的沒有太多事情要做。
到目前為止沒有運氣,所以我在這里分享這個以防其他人遇到相同或類似的問題。
更新: 1 我發現了以下半相關的問題,並讓我在 iOS 13 中找到了 Apple 的新UISceneDelegate 。這些問題都不能解釋為什么沒有調用touchesBegan
。 據我了解UISceneDelegate
到目前為止,我還沒有找到為什么沒有調用touchesBegan
。
視圖控制器響應 iOS 12 中的應用程序委托通知,但不響應 iOS 13
如何檢測狀態欄中的觸摸
iOS13:如何檢測狀態欄點擊事件?
這就是我正在做的,可能不是很好,但目前只是可行的解決方案。 樂於改進。
這也適用於 SceneDelegate。
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)
}
}
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)
}
我最近遇到了同樣的問題。 我花了幾個小時才弄明白。 我在主窗口頂部創建了另一個 UIWindow 來顯示應用程序通知/警報。 出於某種原因,它在使用 ios 13 時會吃掉所有的觸摸動作。我的解決方法是在頂部禁用用戶交互。 但這意味着您顯然無法與通知/警報進行任何用戶交互。
最近我遇到了同樣的問題,尤其是當有一些變換動畫時
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.