Remove toolbar autohiding and add optional fullscreen mode.

This commit is contained in:
Maurice Parker
2019-11-18 19:12:24 -06:00
parent ae254c0bd6
commit fc235a029e
9 changed files with 206 additions and 42 deletions

View File

@@ -0,0 +1,77 @@
//
// InteractiveNavigationController.swift
// NetNewsWire
//
// Created by Maurice Parker on 8/22/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
protocol InteractiveNavigationControllerTappable {
func didTapNavigationBar()
}
class InteractiveNavigationController: UINavigationController {
private let poppableDelegate = PoppableGestureRecognizerDelegate()
static func template() -> UINavigationController {
let navController = InteractiveNavigationController()
navController.configure()
return navController
}
static func template(rootViewController: UIViewController) -> UINavigationController {
let navController = InteractiveNavigationController(rootViewController: rootViewController)
navController.configure()
return navController
}
override func viewDidLoad() {
super.viewDidLoad()
poppableDelegate.originalDelegate = interactivePopGestureRecognizer?.delegate
poppableDelegate.navigationController = self
interactivePopGestureRecognizer?.delegate = poppableDelegate
navigationBar.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapNavigationBar)))
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle {
configure()
}
}
@objc func didTapNavigationBar() {
if let tappable = topViewController as? InteractiveNavigationControllerTappable {
tappable.didTapNavigationBar()
}
}
}
// MARK: Private
private extension InteractiveNavigationController {
func configure() {
isToolbarHidden = false
view.backgroundColor = AppAssets.barBackgroundColor
let navigationAppearance = UINavigationBarAppearance()
navigationAppearance.backgroundColor = AppAssets.barBackgroundColor
navigationAppearance.titleTextAttributes = [.foregroundColor: UIColor.label]
navigationAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.label]
navigationBar.standardAppearance = navigationAppearance
navigationBar.tintColor = AppAssets.primaryAccentColor
let toolbarAppearance = UIToolbarAppearance()
toolbarAppearance.backgroundColor = AppAssets.barBackgroundColor
toolbar.standardAppearance = toolbarAppearance
toolbar.compactAppearance = toolbarAppearance
toolbar.tintColor = AppAssets.primaryAccentColor
}
}

View File

@@ -0,0 +1,40 @@
//
// PoppableGestureRecognizerDelegate.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 11/18/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
// https://stackoverflow.com/a/38042863
import UIKit
final class PoppableGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate {
weak var navigationController: UINavigationController?
weak var originalDelegate: UIGestureRecognizerDelegate?
override func responds(to aSelector: Selector!) -> Bool {
if aSelector == #selector(gestureRecognizer(_:shouldReceive:)) {
return true
} else if let responds = originalDelegate?.responds(to: aSelector) {
return responds
} else {
return false
}
}
override func forwardingTarget(for aSelector: Selector!) -> Any? {
return originalDelegate
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if let nav = navigationController, nav.isNavigationBarHidden, nav.viewControllers.count > 1 {
return true
} else if let result = originalDelegate?.gestureRecognizer?(gestureRecognizer, shouldReceive: touch) {
return result
} else {
return false
}
}
}

View File

@@ -13,7 +13,7 @@ extension UISplitViewController {
static func template() -> UISplitViewController {
let splitViewController = UISplitViewController()
splitViewController.preferredDisplayMode = .automatic
splitViewController.viewControllers = [ThemedNavigationController.template()]
splitViewController.viewControllers = [InteractiveNavigationController.template()]
return splitViewController
}