@@ -36,6 +36,7 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
3636
3737 private var lastLocation : CGPoint = . zero
3838 private var isAnimating : Bool = false
39+ private var maxZoomScale : CGFloat = 1.0
3940
4041 init ( sourceView: UIImageView ? = nil ) {
4142 super. init ( nibName: nil , bundle: nil )
@@ -205,31 +206,33 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
205206
206207 func gestureRecognizerShouldBegin(
207208 _ gestureRecognizer: UIGestureRecognizer ) -> Bool {
208- if let panGesture = gestureRecognizer as? UIPanGestureRecognizer {
209- let velocity = panGesture . velocity ( in : scrollView )
210- return abs ( velocity . y ) > abs ( velocity . x )
211- }
212- return false
209+ guard scrollView . zoomScale == scrollView . minimumZoomScale ,
210+ let panGesture = gestureRecognizer as? UIPanGestureRecognizer else { return false }
211+
212+ let velocity = panGesture . velocity ( in : scrollView )
213+ return abs ( velocity . y ) > abs ( velocity . x )
213214 }
214215}
215216
216217// MARK: Adjusting the dimensions
217218extension ImageViewerController {
218219
219220 func updateMinMaxZoomScaleForSize( _ size: CGSize ) {
220- let widthScale = size. width / imageView. bounds. width
221- let heightScale = size. height / imageView. bounds. height
221+ let widthScale = ( size. width + 1.0 ) / imageView. bounds. width
222+ let heightScale = ( size. height + 1.0 ) / imageView. bounds. height
222223 let minScale = min ( widthScale, heightScale)
224+ let maxScale = max ( widthScale, heightScale)
223225
224226 scrollView. minimumZoomScale = minScale
225227 scrollView. zoomScale = minScale
226- scrollView. maximumZoomScale = max ( 1 , minScale) * 2
228+ maxZoomScale = maxScale
229+ scrollView. maximumZoomScale = maxZoomScale * 1.1
227230 }
228231
229232
230233 func zoomInOrOut( at point: CGPoint ) {
231234 let newZoomScale = scrollView. zoomScale == scrollView. minimumZoomScale
232- ? scrollView . maximumZoomScale : scrollView. minimumZoomScale
235+ ? maxZoomScale : scrollView. minimumZoomScale
233236 let size = scrollView. bounds. size
234237 let w = size. width / newZoomScale
235238 let h = size. height / newZoomScale
0 commit comments