Skip to content

Instantly share code, notes, and snippets.

@sebjvidal
Created June 27, 2023 18:14
Show Gist options
  • Select an option

  • Save sebjvidal/2f2b6500a6c59a7add2d77631d3511a8 to your computer and use it in GitHub Desktop.

Select an option

Save sebjvidal/2f2b6500a6c59a7add2d77631d3511a8 to your computer and use it in GitHub Desktop.

Revisions

  1. sebjvidal created this gist Jun 27, 2023.
    61 changes: 61 additions & 0 deletions SceneDelegate.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    // MARK: - SceneDelegate
    class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    let navigationController = UINavigationController(navigationBarClass: NavigationBar.self, toolbarClass: nil)
    (navigationController.navigationBar as! NavigationBar).preferredHeight = 88
    navigationController.setViewControllers([ViewController()], animated: false)

    guard let windowScene = (scene as? UIWindowScene) else { return }
    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = navigationController
    window.makeKeyAndVisible()
    self.window = window
    }
    }

    // MARK: - NavigationBar
    class NavigationBar: UINavigationBar {

    var preferredHeight: CGFloat = 44

    override var frame: CGRect {
    get {
    return super.frame
    } set {
    var frame = newValue
    frame.size.height = preferredHeight
    super.frame = frame
    }
    }

    override func layoutSubviews() {
    super.layoutSubviews()
    frame = CGRect(x: frame.minX, y: frame.minY, width: frame.width, height: preferredHeight)
    }
    }

    // MARK: - ViewController
    class ViewController: UITableViewController {

    override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    transitionCoordinator?.animate { _ in
    (self.navigationController?.navigationBar as? NavigationBar)?.preferredHeight = 88
    }
    }
    }

    // MARK: - DetailViewController
    class DetailViewController: UITableViewController {

    override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    transitionCoordinator?.animate { _ in
    (self.navigationController?.navigationBar as? NavigationBar)?.preferredHeight = 44

    }
    }
    }