Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexLittlejohn committed Aug 30, 2017
2 parents 5d54704 + 116b93a commit 8dccb17
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ALCameraViewController.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|
spec.name = "ALCameraViewController"
spec.version = "1.4.0"
spec.summary = "A camera view controller with custom image picker and image cropping. Written in Swift."
spec.version = "1.4.1"
spec.summary = "A camera view controller with custom image picker and image cropping."
spec.source = { :git => "https://github.com/AlexLittlejohn/ALCameraViewController.git", :tag => spec.version.to_s }
spec.requires_arc = true
spec.platform = :ios, "8.0"
Expand Down
10 changes: 8 additions & 2 deletions ALCameraViewController/ViewController/CameraViewController.swift
Expand Up @@ -48,6 +48,7 @@ open class CameraViewController: UIViewController {
var didUpdateViews = false
var allowCropping = false
var animationRunning = false
let allowVolumeButtonCapture: Bool

var lastInterfaceOrientation : UIInterfaceOrientation?
open var onCompletion: CameraViewCompletion?
Expand Down Expand Up @@ -158,8 +159,9 @@ open class CameraViewController: UIViewController {

private let allowsLibraryAccess: Bool

public init(croppingEnabled: Bool, allowsLibraryAccess: Bool = true, allowsSwapCameraOrientation: Bool = true, completion: @escaping CameraViewCompletion) {
public init(croppingEnabled: Bool, allowsLibraryAccess: Bool = true, allowsSwapCameraOrientation: Bool = true, allowVolumeButtonCapture: Bool = true, completion: @escaping CameraViewCompletion) {
self.allowsLibraryAccess = allowsLibraryAccess
self.allowVolumeButtonCapture = allowVolumeButtonCapture
super.init(nibName: nil, bundle: nil)
onCompletion = completion
allowCropping = croppingEnabled
Expand Down Expand Up @@ -266,6 +268,7 @@ open class CameraViewController: UIViewController {
setupActions()
checkPermissions()
cameraView.configureFocus()
cameraView.configureZoom()
}

/**
Expand All @@ -276,7 +279,10 @@ open class CameraViewController: UIViewController {
cameraView.startSession()
addCameraObserver()
addRotateObserver()
setupVolumeControl()

if allowVolumeButtonCapture {
setupVolumeControl()
}
}

/**
Expand Down
36 changes: 36 additions & 0 deletions ALCameraViewController/Views/CameraView.swift
Expand Up @@ -100,6 +100,11 @@ public class CameraView: UIView {
line.alpha = 0
}
}

public func configureZoom() {
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinch(gesture:)))
addGestureRecognizer(pinchGesture)
}

internal func focus(gesture: UITapGestureRecognizer) {
let point = gesture.location(in: self)
Expand Down Expand Up @@ -134,6 +139,37 @@ public class CameraView: UIView {
}
})
}

internal func pinch(gesture: UIPinchGestureRecognizer) {
guard let device = device else { return }

// Return zoom value between the minimum and maximum zoom values
func minMaxZoom(_ factor: CGFloat) -> CGFloat {
return min(max(factor, 1.0), device.activeFormat.videoMaxZoomFactor)
}

func update(scale factor: CGFloat) {
do {
try device.lockForConfiguration()
defer { device.unlockForConfiguration() }
device.videoZoomFactor = factor
} catch {
print("\(error.localizedDescription)")
}
}

let velocity = gesture.velocity
let velocityFactor: CGFloat = 8.0
let desiredZoomFactor = device.videoZoomFactor + atan2(velocity, velocityFactor)

let newScaleFactor = minMaxZoom(desiredZoomFactor)
switch gesture.state {
case .began, .changed:
update(scale: newScaleFactor)
case _:
break
}
}

private func createPreview() {

Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,5 +1,5 @@
# ALCameraViewController
A camera view controller with custom image picker and image cropping. Written in Swift.
A camera view controller with custom image picker and image cropping.

![camera](https://cloud.githubusercontent.com/assets/932822/8455694/c61de812-2006-11e5-85c0-a57e3d980561.jpg)
![cropper](https://cloud.githubusercontent.com/assets/932822/8455697/c627ac44-2006-11e5-82be-7f96e73d9b1f.jpg)
Expand Down

0 comments on commit 8dccb17

Please sign in to comment.