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

Commit 8dccb17

Browse files
Merge branch 'release/1.4.1'
2 parents 5d54704 + 116b93a commit 8dccb17

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

ALCameraViewController.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |spec|
22
spec.name = "ALCameraViewController"
3-
spec.version = "1.4.0"
4-
spec.summary = "A camera view controller with custom image picker and image cropping. Written in Swift."
3+
spec.version = "1.4.1"
4+
spec.summary = "A camera view controller with custom image picker and image cropping."
55
spec.source = { :git => "https://github.com/AlexLittlejohn/ALCameraViewController.git", :tag => spec.version.to_s }
66
spec.requires_arc = true
77
spec.platform = :ios, "8.0"

ALCameraViewController/ViewController/CameraViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ open class CameraViewController: UIViewController {
4848
var didUpdateViews = false
4949
var allowCropping = false
5050
var animationRunning = false
51+
let allowVolumeButtonCapture: Bool
5152

5253
var lastInterfaceOrientation : UIInterfaceOrientation?
5354
open var onCompletion: CameraViewCompletion?
@@ -158,8 +159,9 @@ open class CameraViewController: UIViewController {
158159

159160
private let allowsLibraryAccess: Bool
160161

161-
public init(croppingEnabled: Bool, allowsLibraryAccess: Bool = true, allowsSwapCameraOrientation: Bool = true, completion: @escaping CameraViewCompletion) {
162+
public init(croppingEnabled: Bool, allowsLibraryAccess: Bool = true, allowsSwapCameraOrientation: Bool = true, allowVolumeButtonCapture: Bool = true, completion: @escaping CameraViewCompletion) {
162163
self.allowsLibraryAccess = allowsLibraryAccess
164+
self.allowVolumeButtonCapture = allowVolumeButtonCapture
163165
super.init(nibName: nil, bundle: nil)
164166
onCompletion = completion
165167
allowCropping = croppingEnabled
@@ -266,6 +268,7 @@ open class CameraViewController: UIViewController {
266268
setupActions()
267269
checkPermissions()
268270
cameraView.configureFocus()
271+
cameraView.configureZoom()
269272
}
270273

271274
/**
@@ -276,7 +279,10 @@ open class CameraViewController: UIViewController {
276279
cameraView.startSession()
277280
addCameraObserver()
278281
addRotateObserver()
279-
setupVolumeControl()
282+
283+
if allowVolumeButtonCapture {
284+
setupVolumeControl()
285+
}
280286
}
281287

282288
/**

ALCameraViewController/Views/CameraView.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public class CameraView: UIView {
100100
line.alpha = 0
101101
}
102102
}
103+
104+
public func configureZoom() {
105+
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinch(gesture:)))
106+
addGestureRecognizer(pinchGesture)
107+
}
103108

104109
internal func focus(gesture: UITapGestureRecognizer) {
105110
let point = gesture.location(in: self)
@@ -134,6 +139,37 @@ public class CameraView: UIView {
134139
}
135140
})
136141
}
142+
143+
internal func pinch(gesture: UIPinchGestureRecognizer) {
144+
guard let device = device else { return }
145+
146+
// Return zoom value between the minimum and maximum zoom values
147+
func minMaxZoom(_ factor: CGFloat) -> CGFloat {
148+
return min(max(factor, 1.0), device.activeFormat.videoMaxZoomFactor)
149+
}
150+
151+
func update(scale factor: CGFloat) {
152+
do {
153+
try device.lockForConfiguration()
154+
defer { device.unlockForConfiguration() }
155+
device.videoZoomFactor = factor
156+
} catch {
157+
print("\(error.localizedDescription)")
158+
}
159+
}
160+
161+
let velocity = gesture.velocity
162+
let velocityFactor: CGFloat = 8.0
163+
let desiredZoomFactor = device.videoZoomFactor + atan2(velocity, velocityFactor)
164+
165+
let newScaleFactor = minMaxZoom(desiredZoomFactor)
166+
switch gesture.state {
167+
case .began, .changed:
168+
update(scale: newScaleFactor)
169+
case _:
170+
break
171+
}
172+
}
137173

138174
private func createPreview() {
139175

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ALCameraViewController
2-
A camera view controller with custom image picker and image cropping. Written in Swift.
2+
A camera view controller with custom image picker and image cropping.
33

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

0 commit comments

Comments
 (0)