From bce1375ac1e657b3466be632e42eb8e9cb4a8a63 Mon Sep 17 00:00:00 2001 From: Fin Date: Tue, 8 Oct 2024 14:23:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DiPad=E4=B8=8D=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E7=9A=84BUG=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=88=97=E8=A1=A8=E4=B8=AD=E7=94=B1=E4=BA=8EiOS18=20U?= =?UTF-8?q?IKit=20BUG=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bark/AppDelegate.swift | 8 ++++---- Common/Client.swift | 24 ++++++++++++++-------- Controller/BaseViewController.swift | 5 +++-- Controller/MessageListViewController.swift | 4 +--- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Bark/AppDelegate.swift b/Bark/AppDelegate.swift index 6341a6c..0d2fc85 100644 --- a/Bark/AppDelegate.swift +++ b/Bark/AppDelegate.swift @@ -137,7 +137,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } private func notificatonHandler(userInfo: [AnyHashable: Any]) { - let navigationController = Client.shared.currentNavigationController + let viewController = Client.shared.currentSnackbarController func presentController() { let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any] let title = alert?["title"] as? String @@ -182,17 +182,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD if let url = url { items.append(url) } - let controller = UIApplication.shared.keyWindow?.rootViewController + let controller = Client.shared.window?.rootViewController let activityController = UIActivityViewController(activityItems: items, applicationActivities: nil) controller?.present(activityController, animated: true, completion: nil) })) alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil)) - navigationController?.present(alertController, animated: true, completion: nil) + viewController?.present(alertController, animated: true, completion: nil) } - if let presentedController = navigationController?.presentedViewController { + if let presentedController = viewController?.presentedViewController { presentedController.dismiss(animated: false) { presentController() } diff --git a/Common/Client.swift b/Common/Client.swift index 2414069..728541f 100644 --- a/Common/Client.swift +++ b/Common/Client.swift @@ -17,17 +17,23 @@ class Client: NSObject { super.init() } - var currentNavigationController: UINavigationController? { - // TODO: iPad 取值不对 - let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController - let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController - return nav + var window: UIWindow? { + return UIApplication.shared.delegate?.window ?? nil + } + + var currentSnackbarController: BarkSnackbarController? { + return self.window?.rootViewController as? BarkSnackbarController } var currentTabBarController: StateStorageTabBarController? { - // TODO: iPad 取值不对 - let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController - return controller?.rootViewController as? StateStorageTabBarController + guard let snackbarController = self.currentSnackbarController else { + return nil + } + if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad { + return (snackbarController.rootViewController as? BarkSplitViewController)?.compactController + } else { + return snackbarController.rootViewController as? BarkTabBarController + } } let appVersion: String = { @@ -67,7 +73,7 @@ class Client: NSObject { UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true]) { success in if !success { // 打不开Universal Link时,则用内置 safari 打开 - self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil) + self.currentSnackbarController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil) } } } else { diff --git a/Controller/BaseViewController.swift b/Controller/BaseViewController.swift index 74ef5a7..c007d6d 100644 --- a/Controller/BaseViewController.swift +++ b/Controller/BaseViewController.swift @@ -8,13 +8,12 @@ import Material import UIKit + class BaseViewController: UIViewController where T: ViewModel { let viewModel: T init(viewModel: T) { self.viewModel = viewModel super.init(nibName: nil, bundle: nil) - - self.view.backgroundColor = BKColor.background.primary } @available(*, unavailable) @@ -28,6 +27,8 @@ class BaseViewController: UIViewController where T: ViewModel { override func viewDidLoad() { super.viewDidLoad() + self.view.backgroundColor = BKColor.background.primary + if UIDevice.current.userInterfaceIdiom == .pad { navigationItem.largeTitleDisplayMode = .never } else { diff --git a/Controller/MessageListViewController.swift b/Controller/MessageListViewController.swift index 91ef6ea..1f7a890 100644 --- a/Controller/MessageListViewController.swift +++ b/Controller/MessageListViewController.swift @@ -225,9 +225,7 @@ class MessageListViewController: BaseViewController { } private func scrollToTop() { - if self.tableView.visibleCells.count > 0 { - self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true) - } + self.tableView.setContentOffset(CGPoint(x: 0, y: -250), animated: false) } }