From 1dcd5af85eb19e1a660b23eaea715fdd085c2029 Mon Sep 17 00:00:00 2001 From: CypherPoet Date: Wed, 20 Feb 2019 19:01:43 -0500 Subject: [PATCH] Override `traitCollectionDidChange` and use adaptive UI. --- .../Multibrowser/HomeViewController.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/31-ipad-multitasking/Multibrowser/Multibrowser/HomeViewController.swift b/31-ipad-multitasking/Multibrowser/Multibrowser/HomeViewController.swift index 1039686..9a60685 100644 --- a/31-ipad-multitasking/Multibrowser/Multibrowser/HomeViewController.swift +++ b/31-ipad-multitasking/Multibrowser/Multibrowser/HomeViewController.swift @@ -76,6 +76,21 @@ class HomeViewController: UIViewController { } } + /** + - When we have a regular horizontal size class, we'll use horizontal stacking + - When we have a compact horizontal size class, we'll use vertical stacking + */ + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + guard let horizontalSizeClasss = previousTraitCollection?.horizontalSizeClass else { return } + + switch horizontalSizeClasss { + case .regular, .unspecified: + stackView.axis = .horizontal + case .compact: + stackView.axis = .vertical + } + } + @IBAction func addWebView(_ sender: Any) { let webView = WKWebView()