From cf317e15e916183734aba2b0bfcb34a5d9b10c02 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 1 Apr 2024 12:40:30 -0400 Subject: [PATCH] Designed for iPad: Possible fix for gallery content being positioned/sized incorrectly See #446 --- .../Sources/GalleryVC/GalleryItemViewController.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift index c28f1433..4c810c42 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift @@ -43,6 +43,7 @@ class GalleryItemViewController: UIViewController { private(set) var controlsVisible: Bool = true private(set) var scrollAndZoomEnabled = true + private var scrollViewSizeForLastZoomScaleUpdate: CGSize? override var prefersHomeIndicatorAutoHidden: Bool { return !controlsVisible } @@ -219,6 +220,12 @@ class GalleryItemViewController: UIViewController { override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + // When the scrollView size changes, make sure the zoom scale is up-to-date since it depends on the scrollView's bounds. + // This might also fix an issue on macOS (Designed for iPad) where the content isn't placed correctly. See #446 + if scrollViewSizeForLastZoomScaleUpdate != scrollView.bounds.size { + scrollViewSizeForLastZoomScaleUpdate = scrollView.bounds.size + updateZoomScale(resetZoom: true) + } centerContent() } @@ -303,6 +310,8 @@ class GalleryItemViewController: UIViewController { } func updateZoomScale(resetZoom: Bool) { + scrollView.contentSize = content.contentSize + guard scrollAndZoomEnabled else { scrollView.maximumZoomScale = 1 scrollView.minimumZoomScale = 1