Fix controls reappearing when swiping between pages in gallery
This commit is contained in:
parent
565d17970f
commit
0c9f6e02bd
|
@ -47,6 +47,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
|||
var shrinkGestureEnabled = true
|
||||
|
||||
private var isInitialAppearance = true
|
||||
private var skipUpdatingControlsWhileZooming = false
|
||||
private var prevZoomScale: CGFloat?
|
||||
private var isGrayscale = false
|
||||
private var contentViewSizeObservation: NSKeyValueObservation?
|
||||
|
@ -216,9 +217,11 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
|||
let heightScale = maxHeight / contentView.intrinsicContentSize.height
|
||||
let widthScale = view.bounds.width / contentView.intrinsicContentSize.width
|
||||
let minScale = min(widthScale, heightScale)
|
||||
skipUpdatingControlsWhileZooming = true
|
||||
scrollView.minimumZoomScale = minScale
|
||||
scrollView.zoomScale = minScale
|
||||
scrollView.maximumZoomScale = minScale >= 1 ? minScale + 2 : 2
|
||||
skipUpdatingControlsWhileZooming = false
|
||||
|
||||
centerImage()
|
||||
|
||||
|
@ -248,6 +251,12 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
|||
}
|
||||
}
|
||||
|
||||
override func viewSafeAreaInsetsDidChange() {
|
||||
super.viewSafeAreaInsetsDidChange()
|
||||
// the controls view transforms take the safe area insets into account, so they need to be updated
|
||||
updateControlsView()
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
|
@ -285,7 +294,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
|||
}
|
||||
|
||||
func updateControlsView() {
|
||||
let topOffset = self.controlsVisible ? 0 : -self.topControlsView.bounds.height
|
||||
let topOffset = self.controlsVisible ? 0 : -(self.topControlsView.bounds.height + self.view.safeAreaInsets.top)
|
||||
self.topControlsView.transform = CGAffineTransform(translationX: 0, y: topOffset)
|
||||
if self.imageDescription != nil {
|
||||
let bottomOffset = self.controlsVisible ? 0 : self.descriptionTextView.bounds.height + self.view.safeAreaInsets.bottom
|
||||
|
@ -299,10 +308,12 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
|||
|
||||
func scrollViewDidZoom(_ scrollView: UIScrollView) {
|
||||
let prevZoomScale = self.prevZoomScale ?? scrollView.minimumZoomScale
|
||||
if scrollView.zoomScale <= scrollView.minimumZoomScale {
|
||||
setControlsVisible(true, animated: true)
|
||||
} else if scrollView.zoomScale > prevZoomScale {
|
||||
setControlsVisible(false, animated: true)
|
||||
if !skipUpdatingControlsWhileZooming {
|
||||
if scrollView.zoomScale <= scrollView.minimumZoomScale {
|
||||
setControlsVisible(true, animated: true)
|
||||
} else if scrollView.zoomScale > prevZoomScale {
|
||||
setControlsVisible(false, animated: true)
|
||||
}
|
||||
}
|
||||
self.prevZoomScale = scrollView.zoomScale
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue