From 7e1cd5d5f6efe4f8771da7bab241d192f314ae90 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 12 Sep 2018 22:29:58 -0400 Subject: [PATCH] Fix large image view top controls on iPhone Xs Max & Xr --- Tusker/Controllers/MastodonController.swift | 6 ++--- .../Screens/Large Image/LargeImage.storyboard | 4 ++-- .../LargeImageViewController.swift | 24 +++++++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Tusker/Controllers/MastodonController.swift b/Tusker/Controllers/MastodonController.swift index 9925e0db..1987c998 100644 --- a/Tusker/Controllers/MastodonController.swift +++ b/Tusker/Controllers/MastodonController.swift @@ -25,9 +25,9 @@ class MastodonController { client = Client(baseURL: url) - if let accessToken = LocalData.shared.accessToken { - client.accessToken = accessToken - } + client.clientID = LocalData.shared.clientID + client.clientSecret = LocalData.shared.clientSecret + client.accessToken = LocalData.shared.accessToken } func registerApp(completion: @escaping () -> Void) { diff --git a/Tusker/Screens/Large Image/LargeImage.storyboard b/Tusker/Screens/Large Image/LargeImage.storyboard index f49180c9..1e5794e0 100644 --- a/Tusker/Screens/Large Image/LargeImage.storyboard +++ b/Tusker/Screens/Large Image/LargeImage.storyboard @@ -1,10 +1,10 @@ - + - + diff --git a/Tusker/Screens/Large Image/LargeImageViewController.swift b/Tusker/Screens/Large Image/LargeImageViewController.swift index fa1e1984..d06884be 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.swift +++ b/Tusker/Screens/Large Image/LargeImageViewController.swift @@ -47,6 +47,8 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate { @IBOutlet weak var bottomControlsView: UIView! @IBOutlet weak var descriptionLabel: UILabel! + var initializedTopControlsConstrains = false + var image: UIImage? var imageDescription: String? @@ -82,23 +84,31 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate { bottomControlsView.isHidden = true } - // if running on iPhone X - if UIScreen.main.nativeBounds.height == 2436 { - topControlsHeightConstraint.constant = 35 - downloadButtonLeadingConstraint.constant = 35 - closeButtonTrailingConstraint.constant = 35 - } - dismissInteractionController = LargeImageInteractionController(viewController: self) } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + let widthScale = view.bounds.size.width / imageView.bounds.width let heightScale = view.bounds.size.height / imageView.bounds.height let minScale = min(widthScale, heightScale) scrollView.minimumZoomScale = minScale scrollView.zoomScale = minScale scrollView.maximumZoomScale = minScale >= 1 ? minScale + 2 : 2 + + if !initializedTopControlsConstrains { + initializedTopControlsConstrains = true + if view.safeAreaInsets.top == 44 { + // running on iPhone X style notched device + let notchWidth: CGFloat = 209 + let earWidth = (view.bounds.width - notchWidth) / 2 + let offset = (earWidth - downloadButton.bounds.width) / 2 + downloadButtonLeadingConstraint.constant = offset + closeButtonTrailingConstraint.constant = offset + } + } } func viewForZooming(in scrollView: UIScrollView) -> UIView? {