Designed for iPad: Possible fix for gallery content being positioned/sized incorrectly

See #446
This commit is contained in:
Shadowfacts 2024-04-01 12:40:30 -04:00
parent bcae60316b
commit cf317e15e9
1 changed files with 9 additions and 0 deletions

View File

@ -43,6 +43,7 @@ class GalleryItemViewController: UIViewController {
private(set) var controlsVisible: Bool = true private(set) var controlsVisible: Bool = true
private(set) var scrollAndZoomEnabled = true private(set) var scrollAndZoomEnabled = true
private var scrollViewSizeForLastZoomScaleUpdate: CGSize?
override var prefersHomeIndicatorAutoHidden: Bool { override var prefersHomeIndicatorAutoHidden: Bool {
return !controlsVisible return !controlsVisible
} }
@ -219,6 +220,12 @@ class GalleryItemViewController: UIViewController {
override func viewDidLayoutSubviews() { override func viewDidLayoutSubviews() {
super.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() centerContent()
} }
@ -303,6 +310,8 @@ class GalleryItemViewController: UIViewController {
} }
func updateZoomScale(resetZoom: Bool) { func updateZoomScale(resetZoom: Bool) {
scrollView.contentSize = content.contentSize
guard scrollAndZoomEnabled else { guard scrollAndZoomEnabled else {
scrollView.maximumZoomScale = 1 scrollView.maximumZoomScale = 1
scrollView.minimumZoomScale = 1 scrollView.minimumZoomScale = 1