@@ -67,7 +67,6 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
6767 scrollView. backgroundColor = . clear
6868
6969 imageView = UIImageView ( frame: . zero)
70- imageView. backgroundColor = . gray
7170 scrollView. addSubview ( imageView)
7271
7372 imageView. translatesAutoresizingMaskIntoConstraints = false
@@ -138,7 +137,7 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
138137
139138 override func viewWillLayoutSubviews( ) {
140139 super. viewWillLayoutSubviews ( )
141- updateMinZoomScaleForSize ( view. bounds. size)
140+ updateMinMaxZoomScaleForSize ( view. bounds. size)
142141 }
143142
144143 func addGestureRecognizers( ) {
@@ -166,18 +165,18 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
166165 doubleTapRecognizer. numberOfTapsRequired = 2
167166 doubleTapRecognizer. numberOfTouchesRequired = 1
168167 scrollView. addGestureRecognizer ( doubleTapRecognizer)
169- scrollView. maximumZoomScale = 4.0
170-
168+
171169 singleTapGesture. require ( toFail: doubleTapRecognizer)
172170 }
173171
174- func updateMinZoomScaleForSize ( _ size: CGSize ) {
172+ func updateMinMaxZoomScaleForSize ( _ size: CGSize ) {
175173 let widthScale = size. width / imageView. bounds. width
176174 let heightScale = size. height / imageView. bounds. height
177175 let minScale = min ( widthScale, heightScale)
178176
179177 scrollView. minimumZoomScale = minScale
180178 scrollView. zoomScale = minScale
179+ scrollView. maximumZoomScale = max ( 1 , minScale) * 2
181180 }
182181
183182 @objc
0 commit comments