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

Commit 7b9c516

Browse files
Merge branch 'release/2.0.0'
2 parents 8dccb17 + df98b19 commit 7b9c516

File tree

11 files changed

+388
-130
lines changed

11 files changed

+388
-130
lines changed

ALCameraViewController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "ALCameraViewController"
3-
spec.version = "1.4.1"
3+
spec.version = "2.0.0"
44
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

ALCameraViewController.xcodeproj/project.pbxproj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
7AC96FA21F5B5166003E53F4 /* CroppingParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AC96FA11F5B5166003E53F4 /* CroppingParameters.swift */; };
1011
C40665441C73A47C00EB9751 /* SingleImageSaver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40665431C73A47C00EB9751 /* SingleImageSaver.swift */; };
1112
C40665461C73A94100EB9751 /* CameraGlobals.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40665451C73A94100EB9751 /* CameraGlobals.swift */; };
1213
C40665481C73B72D00EB9751 /* SingleImageFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40665471C73B72D00EB9751 /* SingleImageFetcher.swift */; };
@@ -58,6 +59,7 @@
5859
/* End PBXBuildFile section */
5960

6061
/* Begin PBXFileReference section */
62+
7AC96FA11F5B5166003E53F4 /* CroppingParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CroppingParameters.swift; sourceTree = "<group>"; };
6163
C40665431C73A47C00EB9751 /* SingleImageSaver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleImageSaver.swift; sourceTree = "<group>"; };
6264
C40665451C73A94100EB9751 /* CameraGlobals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraGlobals.swift; sourceTree = "<group>"; };
6365
C40665471C73B72D00EB9751 /* SingleImageFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleImageFetcher.swift; sourceTree = "<group>"; };
@@ -154,6 +156,7 @@
154156
C4D9BA441CA7224B004F70F7 /* PhotoLibraryAuthorizer.swift */,
155157
C4D9BA461CA73163004F70F7 /* UIButtonExtensions.swift */,
156158
EBFE097C1CAF1D1A00A8C637 /* UIViewExtensions.swift */,
159+
7AC96FA11F5B5166003E53F4 /* CroppingParameters.swift */,
157160
);
158161
path = Utilities;
159162
sourceTree = "<group>";
@@ -267,7 +270,7 @@
267270
attributes = {
268271
LastSwiftMigration = 0700;
269272
LastSwiftUpdateCheck = 0700;
270-
LastUpgradeCheck = 0800;
273+
LastUpgradeCheck = 0900;
271274
ORGANIZATIONNAME = zero;
272275
TargetAttributes = {
273276
C4829FFA1CAEB16C00541D08 = {
@@ -366,6 +369,7 @@
366369
FAB50C001B413E8C009905B9 /* PhotoLibraryViewController.swift in Sources */,
367370
FAF0586A1B317894008E5592 /* CameraShot.swift in Sources */,
368371
FAF058661B316695008E5592 /* CameraViewController.swift in Sources */,
372+
7AC96FA21F5B5166003E53F4 /* CroppingParameters.swift in Sources */,
369373
C4D9BA451CA7224B004F70F7 /* PhotoLibraryAuthorizer.swift in Sources */,
370374
FAB50BFB1B413E8C009905B9 /* ImageCell.swift in Sources */,
371375
EBFE097D1CAF1D1A00A8C637 /* UIViewExtensions.swift in Sources */,
@@ -438,14 +442,20 @@
438442
CLANG_CXX_LIBRARY = "libc++";
439443
CLANG_ENABLE_MODULES = YES;
440444
CLANG_ENABLE_OBJC_ARC = YES;
445+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
441446
CLANG_WARN_BOOL_CONVERSION = YES;
447+
CLANG_WARN_COMMA = YES;
442448
CLANG_WARN_CONSTANT_CONVERSION = YES;
443449
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
444450
CLANG_WARN_EMPTY_BODY = YES;
445451
CLANG_WARN_ENUM_CONVERSION = YES;
446452
CLANG_WARN_INFINITE_RECURSION = YES;
447453
CLANG_WARN_INT_CONVERSION = YES;
454+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
455+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
448456
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
457+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
458+
CLANG_WARN_STRICT_PROTOTYPES = YES;
449459
CLANG_WARN_SUSPICIOUS_MOVE = YES;
450460
CLANG_WARN_UNREACHABLE_CODE = YES;
451461
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -486,14 +496,20 @@
486496
CLANG_CXX_LIBRARY = "libc++";
487497
CLANG_ENABLE_MODULES = YES;
488498
CLANG_ENABLE_OBJC_ARC = YES;
499+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
489500
CLANG_WARN_BOOL_CONVERSION = YES;
501+
CLANG_WARN_COMMA = YES;
490502
CLANG_WARN_CONSTANT_CONVERSION = YES;
491503
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
492504
CLANG_WARN_EMPTY_BODY = YES;
493505
CLANG_WARN_ENUM_CONVERSION = YES;
494506
CLANG_WARN_INFINITE_RECURSION = YES;
495507
CLANG_WARN_INT_CONVERSION = YES;
508+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
509+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
496510
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
511+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
512+
CLANG_WARN_STRICT_PROTOTYPES = YES;
497513
CLANG_WARN_SUSPICIOUS_MOVE = YES;
498514
CLANG_WARN_UNREACHABLE_CODE = YES;
499515
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

ALCameraViewController.xcodeproj/xcshareddata/xcschemes/CameraViewController.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -36,6 +37,7 @@
3637
buildConfiguration = "Debug"
3738
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3839
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
40+
language = ""
3941
launchStyle = "0"
4042
useCustomWorkingDirectory = "NO"
4143
ignoresPersistentStateOnLaunch = "NO"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// CroppingParameters.swift
3+
// ALCameraViewController
4+
//
5+
// Created by Guillaume Bellut on 02/09/2017.
6+
// Copyright © 2017 zero. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public struct CroppingParameters {
12+
13+
/// Enable the cropping feature.
14+
/// Default value is set to false.
15+
var isEnabled: Bool
16+
17+
/// Allow the cropping area to be resized by the user.
18+
/// Default value is set to true.
19+
var allowResizing: Bool
20+
21+
/// Allow the cropping area to be moved by the user.
22+
/// Default value is set to false.
23+
var allowMoving: Bool
24+
25+
/// Prevent the user to resize the cropping area below a minimum size.
26+
/// Default value is (60, 60). Below this value, corner buttons will overlap.
27+
var minimumSize: CGSize
28+
29+
public init(isEnabled: Bool = false,
30+
allowResizing: Bool = true,
31+
allowMoving: Bool = true,
32+
minimumSize: CGSize = CGSize(width: 60, height: 60)) {
33+
34+
self.isEnabled = isEnabled
35+
self.allowResizing = allowResizing
36+
self.allowMoving = allowMoving
37+
self.minimumSize = minimumSize
38+
}
39+
}

ALCameraViewController/Utilities/SingleImageFetcher.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ public class SingleImageFetcher {
7878
options.resizeMode = .exact
7979

8080
let targetWidth = floor(CGFloat(asset.pixelWidth) * cropRect.width)
81-
let targetHeight = floor(CGFloat(asset.pixelHeight) * cropRect.height)
82-
let dimension = max(min(targetHeight, targetWidth), 1024 * scale)
83-
84-
targetSize = CGSize(width: dimension, height: dimension)
81+
let targetHeight = floor(CGFloat(asset.pixelHeight) * cropRect.height)
82+
83+
targetSize = CGSize(width: targetWidth, height: targetHeight)
8584
}
86-
85+
8786
PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFill, options: options) { image, _ in
8887
if let image = image {
8988
self.success?(image)

ALCameraViewController/ViewController/CameraViewController.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public typealias CameraViewCompletion = (UIImage?, PHAsset?) -> Void
1414

1515
public extension CameraViewController {
1616
/// Provides an image picker wrapped inside a UINavigationController instance
17-
public class func imagePickerViewController(croppingEnabled: Bool, completion: @escaping CameraViewCompletion) -> UINavigationController {
17+
public class func imagePickerViewController(croppingParameters: CroppingParameters, completion: @escaping CameraViewCompletion) -> UINavigationController {
1818
let imagePicker = PhotoLibraryViewController()
1919
let navigationController = UINavigationController(rootViewController: imagePicker)
2020

@@ -24,7 +24,7 @@ public extension CameraViewController {
2424

2525
imagePicker.onSelectionComplete = { [weak imagePicker] asset in
2626
if let asset = asset {
27-
let confirmController = ConfirmViewController(asset: asset, allowsCropping: croppingEnabled)
27+
let confirmController = ConfirmViewController(asset: asset, croppingParameters: croppingParameters)
2828
confirmController.onComplete = { [weak imagePicker] image, asset in
2929
if let image = image, let asset = asset {
3030
completion(image, asset)
@@ -46,7 +46,7 @@ public extension CameraViewController {
4646
open class CameraViewController: UIViewController {
4747

4848
var didUpdateViews = false
49-
var allowCropping = false
49+
var croppingParameters: CroppingParameters
5050
var animationRunning = false
5151
let allowVolumeButtonCapture: Bool
5252

@@ -89,7 +89,7 @@ open class CameraViewController: UIViewController {
8989
cameraView.translatesAutoresizingMaskIntoConstraints = false
9090
return cameraView
9191
}()
92-
92+
9393
let cameraOverlay : CropOverlay = {
9494
let cameraOverlay = CropOverlay()
9595
cameraOverlay.translatesAutoresizingMaskIntoConstraints = false
@@ -159,13 +159,18 @@ open class CameraViewController: UIViewController {
159159

160160
private let allowsLibraryAccess: Bool
161161

162-
public init(croppingEnabled: Bool, allowsLibraryAccess: Bool = true, allowsSwapCameraOrientation: Bool = true, allowVolumeButtonCapture: Bool = true, completion: @escaping CameraViewCompletion) {
163-
self.allowsLibraryAccess = allowsLibraryAccess
162+
public init(croppingParameters: CroppingParameters = CroppingParameters(),
163+
allowsLibraryAccess: Bool = true,
164+
allowsSwapCameraOrientation: Bool = true,
165+
allowVolumeButtonCapture: Bool = true,
166+
completion: @escaping CameraViewCompletion) {
167+
168+
self.croppingParameters = croppingParameters
169+
self.allowsLibraryAccess = allowsLibraryAccess
164170
self.allowVolumeButtonCapture = allowVolumeButtonCapture
165171
super.init(nibName: nil, bundle: nil)
166172
onCompletion = completion
167-
allowCropping = croppingEnabled
168-
cameraOverlay.isHidden = !allowCropping
173+
cameraOverlay.isHidden = !croppingParameters.isEnabled
169174
libraryButton.isEnabled = allowsLibraryAccess
170175
libraryButton.isHidden = !allowsLibraryAccess
171176
swapButton.isEnabled = allowsSwapCameraOrientation
@@ -539,7 +544,7 @@ open class CameraViewController: UIViewController {
539544
}
540545

541546
internal func showLibrary() {
542-
let imagePicker = CameraViewController.imagePickerViewController(croppingEnabled: allowCropping) { [weak self] image, asset in
547+
let imagePicker = CameraViewController.imagePickerViewController(croppingParameters: croppingParameters) { [weak self] image, asset in
543548
defer {
544549
self?.dismiss(animated: true, completion: nil)
545550
}
@@ -588,7 +593,7 @@ open class CameraViewController: UIViewController {
588593
}
589594

590595
private func startConfirmController(uiImage: UIImage) {
591-
let confirmViewController = ConfirmViewController(image: uiImage, allowsCropping: allowCropping)
596+
let confirmViewController = ConfirmViewController(image: uiImage, croppingParameters: croppingParameters)
592597
confirmViewController.onComplete = { [weak self] image, asset in
593598
defer {
594599
self?.dismiss(animated: true, completion: nil)
@@ -606,7 +611,7 @@ open class CameraViewController: UIViewController {
606611
}
607612

608613
private func startConfirmController(asset: PHAsset) {
609-
let confirmViewController = ConfirmViewController(asset: asset, allowsCropping: allowCropping)
614+
let confirmViewController = ConfirmViewController(asset: asset, croppingParameters: croppingParameters)
610615
confirmViewController.onComplete = { [weak self] image, asset in
611616
defer {
612617
self?.dismiss(animated: true, completion: nil)

0 commit comments

Comments
 (0)