forked from shadowfacts/Tusker
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
|
var shrinkGestureEnabled = true
|
||||||
|
|
||||||
private var isInitialAppearance = true
|
private var isInitialAppearance = true
|
||||||
|
private var skipUpdatingControlsWhileZooming = false
|
||||||
private var prevZoomScale: CGFloat?
|
private var prevZoomScale: CGFloat?
|
||||||
private var isGrayscale = false
|
private var isGrayscale = false
|
||||||
private var contentViewSizeObservation: NSKeyValueObservation?
|
private var contentViewSizeObservation: NSKeyValueObservation?
|
||||||
|
@ -216,9 +217,11 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
||||||
let heightScale = maxHeight / contentView.intrinsicContentSize.height
|
let heightScale = maxHeight / contentView.intrinsicContentSize.height
|
||||||
let widthScale = view.bounds.width / contentView.intrinsicContentSize.width
|
let widthScale = view.bounds.width / contentView.intrinsicContentSize.width
|
||||||
let minScale = min(widthScale, heightScale)
|
let minScale = min(widthScale, heightScale)
|
||||||
|
skipUpdatingControlsWhileZooming = true
|
||||||
scrollView.minimumZoomScale = minScale
|
scrollView.minimumZoomScale = minScale
|
||||||
scrollView.zoomScale = minScale
|
scrollView.zoomScale = minScale
|
||||||
scrollView.maximumZoomScale = minScale >= 1 ? minScale + 2 : 2
|
scrollView.maximumZoomScale = minScale >= 1 ? minScale + 2 : 2
|
||||||
|
skipUpdatingControlsWhileZooming = false
|
||||||
|
|
||||||
centerImage()
|
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) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
|
@ -285,7 +294,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateControlsView() {
|
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)
|
self.topControlsView.transform = CGAffineTransform(translationX: 0, y: topOffset)
|
||||||
if self.imageDescription != nil {
|
if self.imageDescription != nil {
|
||||||
let bottomOffset = self.controlsVisible ? 0 : self.descriptionTextView.bounds.height + self.view.safeAreaInsets.bottom
|
let bottomOffset = self.controlsVisible ? 0 : self.descriptionTextView.bounds.height + self.view.safeAreaInsets.bottom
|
||||||
|
@ -299,11 +308,13 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
||||||
|
|
||||||
func scrollViewDidZoom(_ scrollView: UIScrollView) {
|
func scrollViewDidZoom(_ scrollView: UIScrollView) {
|
||||||
let prevZoomScale = self.prevZoomScale ?? scrollView.minimumZoomScale
|
let prevZoomScale = self.prevZoomScale ?? scrollView.minimumZoomScale
|
||||||
|
if !skipUpdatingControlsWhileZooming {
|
||||||
if scrollView.zoomScale <= scrollView.minimumZoomScale {
|
if scrollView.zoomScale <= scrollView.minimumZoomScale {
|
||||||
setControlsVisible(true, animated: true)
|
setControlsVisible(true, animated: true)
|
||||||
} else if scrollView.zoomScale > prevZoomScale {
|
} else if scrollView.zoomScale > prevZoomScale {
|
||||||
setControlsVisible(false, animated: true)
|
setControlsVisible(false, animated: true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self.prevZoomScale = scrollView.zoomScale
|
self.prevZoomScale = scrollView.zoomScale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue