Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Sources/ImageViewerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
scrollView.backgroundColor = .clear

imageView = UIImageView(frame: .zero)
imageView.backgroundColor = .gray
scrollView.addSubview(imageView)

imageView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -138,7 +137,7 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
updateMinZoomScaleForSize(view.bounds.size)
updateMinMaxZoomScaleForSize(view.bounds.size)
}

func addGestureRecognizers() {
Expand Down Expand Up @@ -166,18 +165,18 @@ class ImageViewerController:UIViewController, UIGestureRecognizerDelegate {
doubleTapRecognizer.numberOfTapsRequired = 2
doubleTapRecognizer.numberOfTouchesRequired = 1
scrollView.addGestureRecognizer(doubleTapRecognizer)
scrollView.maximumZoomScale = 4.0


singleTapGesture.require(toFail: doubleTapRecognizer)
}

func updateMinZoomScaleForSize(_ size: CGSize) {
func updateMinMaxZoomScaleForSize(_ size: CGSize) {
let widthScale = size.width / imageView.bounds.width
let heightScale = size.height / imageView.bounds.height
let minScale = min(widthScale, heightScale)

scrollView.minimumZoomScale = minScale
scrollView.zoomScale = minScale
scrollView.maximumZoomScale = max(1, minScale) * 2
}

@objc
Expand Down