Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Pinch to Zoom support #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions Sources/Gallery/Camera/CameraController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class CameraController: UIViewController {
cameraView.stackView.addTarget(self, action: #selector(stackViewTouched(_:)), for: .touchUpInside)
cameraView.shutterButton.addTarget(self, action: #selector(shutterButtonTouched(_:)), for: .touchUpInside)
cameraView.doneButton.addTarget(self, action: #selector(doneButtonTouched(_:)), for: .touchUpInside)

let pinchRecognizer = UIPinchGestureRecognizer(target: self, action:#selector(pinch(_:)))
cameraView.addGestureRecognizer(pinchRecognizer)
}

func setupLocation() {
Expand Down Expand Up @@ -161,6 +164,29 @@ class CameraController: UIViewController {

return view
}

@objc func pinch(_ pinch : UIPinchGestureRecognizer) {
guard let device = cameraMan.currentInput?.device else { return }
let zoomFactor = device.videoZoomFactor * pinch.scale
pinch.scale = 1.0

let minZoomFactor = max(Config.Camera.minZoomFactor, device.minAvailableVideoZoomFactor)
let maxZoomFactor = min(Config.Camera.maxZoomFactor, device.maxAvailableVideoZoomFactor)
do {
try device.lockForConfiguration()

defer {
device.unlockForConfiguration()
}

if (zoomFactor <= maxZoomFactor && zoomFactor >= minZoomFactor) {
device.videoZoomFactor = zoomFactor
}

} catch {
assertionFailure("Unable to set video zoom factor")
}
}
}

extension CameraController: CartDelegate {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Gallery/Utils/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public struct Config {
}

public static var imageLimit: Int = 0

public static var minZoomFactor: CGFloat = 1

public static var maxZoomFactor: CGFloat = 10

}

Expand Down