From 7f2bd494b5743f7904a0b45156832c716dd2faad Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 4 Apr 2023 17:12:18 -0500 Subject: [PATCH] Fixes tapping buttons underneath navigation bar on SourceDetailViewController/AppViewController --- AltStore/App Detail/AppViewController.swift | 4 ++- .../HeaderContentViewController.swift | 4 ++- AltStore/Components/NavigationBar.swift | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/AltStore/App Detail/AppViewController.swift b/AltStore/App Detail/AppViewController.swift index 809427c5..7cca5eb1 100644 --- a/AltStore/App Detail/AppViewController.swift +++ b/AltStore/App Detail/AppViewController.swift @@ -416,15 +416,17 @@ private extension AppViewController // Copied from HeaderContentViewController func updateNavigationBarAppearance(isHidden: Bool) { - let barAppearance = self.navigationItem.standardAppearance ?? UINavigationBarAppearance() + let barAppearance = self.navigationItem.standardAppearance as? NavigationBarAppearance ?? NavigationBarAppearance() if isHidden { barAppearance.configureWithTransparentBackground() + barAppearance.ignoresUserInteraction = true } else { barAppearance.configureWithDefaultBackground() + barAppearance.ignoresUserInteraction = false } barAppearance.titleTextAttributes = [.foregroundColor: UIColor.clear] diff --git a/AltStore/Components/HeaderContentViewController.swift b/AltStore/Components/HeaderContentViewController.swift index c4da27c6..76b41a9d 100644 --- a/AltStore/Components/HeaderContentViewController.swift +++ b/AltStore/Components/HeaderContentViewController.swift @@ -481,15 +481,17 @@ private extension HeaderContentViewController func updateNavigationBarAppearance(isHidden: Bool) { - let barAppearance = self.navigationItem.standardAppearance ?? UINavigationBarAppearance() + let barAppearance = self.navigationItem.standardAppearance as? NavigationBarAppearance ?? NavigationBarAppearance() if isHidden { barAppearance.configureWithTransparentBackground() + barAppearance.ignoresUserInteraction = true } else { barAppearance.configureWithDefaultBackground() + barAppearance.ignoresUserInteraction = false } barAppearance.titleTextAttributes = [.foregroundColor: UIColor.clear] diff --git a/AltStore/Components/NavigationBar.swift b/AltStore/Components/NavigationBar.swift index 2beb2789..5f1d25d6 100644 --- a/AltStore/Components/NavigationBar.swift +++ b/AltStore/Components/NavigationBar.swift @@ -12,6 +12,20 @@ import Roxas final class NavigationBar: UINavigationBar { + // We sometimes need to ignore user interaction so + // we can tap items underneath the navigation bar. + var ignoresUserInteraction: Bool = false + + override func copy(with zone: NSZone? = nil) -> Any + { + let copy = super.copy(with: zone) as! NavigationBarAppearance + copy.ignoresUserInteraction = self.ignoresUserInteraction + return copy + } +} + +class NavigationBar: UINavigationBar +{ @IBInspectable var automaticallyAdjustsItemPositions: Bool = true private let backgroundColorView = UIView() @@ -80,4 +94,15 @@ final class NavigationBar: UINavigationBar } } } + + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? + { + if let appearance = self.topItem?.standardAppearance as? NavigationBarAppearance, appearance.ignoresUserInteraction + { + // Ignore touches. + return nil + } + + return super.hitTest(point, with: event) + } }