Large Image VC: Don't let image overlap top controls when zoomed out

This commit is contained in:
Shadowfacts 2019-06-14 15:27:17 -07:00
parent ea143ea0dd
commit bd8e16cacb
Signed by: shadowfacts
GPG Key ID: 83FB3304046BADA4
1 changed files with 5 additions and 2 deletions

View File

@ -118,8 +118,11 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
override func viewDidLayoutSubviews() { override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews() super.viewDidLayoutSubviews()
let widthScale = view.bounds.size.width / imageView.bounds.width // limit the image height to the safe area height, so the image doesn't overlap the top controls
let heightScale = view.bounds.size.height / imageView.bounds.height // while zoomed all the way out
let maxHeight = view.bounds.height - view.safeAreaInsets.top - view.safeAreaInsets.bottom
let heightScale = maxHeight / imageView.bounds.height
let widthScale = view.bounds.width / imageView.bounds.width
let minScale = min(widthScale, heightScale) let minScale = min(widthScale, heightScale)
scrollView.minimumZoomScale = minScale scrollView.minimumZoomScale = minScale
scrollView.zoomScale = minScale scrollView.zoomScale = minScale