From 18f5bf280e32c804d79308dc0854ed9a76d69895 Mon Sep 17 00:00:00 2001
From: Orcas Development <>
Date: Tue, 2 Apr 2019 19:28:44 +0200
Subject: [PATCH 1/3] allow Square Crop
---
ALCameraViewController.xcodeproj/project.pbxproj | 6 +++---
.../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++
ALCameraViewController/Utilities/CroppingParameters.swift | 4 ++++
.../ViewController/ConfirmViewController.swift | 2 ++
ALCameraViewController/Views/CropOverlay.swift | 7 +++++--
Example/ViewController.swift | 6 +++---
6 files changed, 25 insertions(+), 8 deletions(-)
create mode 100644 ALCameraViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
diff --git a/ALCameraViewController.xcodeproj/project.pbxproj b/ALCameraViewController.xcodeproj/project.pbxproj
index 720f06f0..de93673d 100644
--- a/ALCameraViewController.xcodeproj/project.pbxproj
+++ b/ALCameraViewController.xcodeproj/project.pbxproj
@@ -283,7 +283,7 @@
};
FAF0583E1B31618D008E5592 = {
CreatedOnToolsVersion = 6.3.2;
- DevelopmentTeam = 2466624KEK;
+ DevelopmentTeam = FX2Z63PGT5;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
@@ -548,7 +548,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- DEVELOPMENT_TEAM = 2466624KEK;
+ DEVELOPMENT_TEAM = FX2Z63PGT5;
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -564,7 +564,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- DEVELOPMENT_TEAM = 2466624KEK;
+ DEVELOPMENT_TEAM = FX2Z63PGT5;
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
diff --git a/ALCameraViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ALCameraViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644
index 00000000..18d98100
--- /dev/null
+++ b/ALCameraViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
@@ -0,0 +1,8 @@
+
+
+
+
+ IDEDidComputeMac32BitWarning
+
+
+
diff --git a/ALCameraViewController/Utilities/CroppingParameters.swift b/ALCameraViewController/Utilities/CroppingParameters.swift
index 88f90acf..b78636ca 100644
--- a/ALCameraViewController/Utilities/CroppingParameters.swift
+++ b/ALCameraViewController/Utilities/CroppingParameters.swift
@@ -21,6 +21,8 @@ public struct CroppingParameters {
/// Allow the cropping area to be moved by the user.
/// Default value is set to false.
var allowMoving: Bool
+
+ var squarableCrop: Bool
/// Prevent the user to resize the cropping area below a minimum size.
/// Default value is (60, 60). Below this value, corner buttons will overlap.
@@ -29,11 +31,13 @@ public struct CroppingParameters {
public init(isEnabled: Bool = false,
allowResizing: Bool = true,
allowMoving: Bool = true,
+ squarableCrop: Bool = true,
minimumSize: CGSize = CGSize(width: 60, height: 60)) {
self.isEnabled = isEnabled
self.allowResizing = allowResizing
self.allowMoving = allowMoving
self.minimumSize = minimumSize
+ self.squarableCrop = squarableCrop
}
}
diff --git a/ALCameraViewController/ViewController/ConfirmViewController.swift b/ALCameraViewController/ViewController/ConfirmViewController.swift
index 5c7fb257..fc949149 100644
--- a/ALCameraViewController/ViewController/ConfirmViewController.swift
+++ b/ALCameraViewController/ViewController/ConfirmViewController.swift
@@ -20,6 +20,7 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
var croppingParameters: CroppingParameters {
didSet {
+ cropOverlay.isSquarable = croppingParameters.squarableCrop
cropOverlay.isResizable = croppingParameters.allowResizing
cropOverlay.minimumSize = croppingParameters.minimumSize
}
@@ -71,6 +72,7 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
cropOverlay.isHidden = true
cropOverlay.isResizable = croppingParameters.allowResizing
cropOverlay.isMovable = croppingParameters.allowMoving
+ cropOverlay.isSquarable = croppingParameters.squarableCrop
cropOverlay.minimumSize = croppingParameters.minimumSize
let spinner = showSpinner()
diff --git a/ALCameraViewController/Views/CropOverlay.swift b/ALCameraViewController/Views/CropOverlay.swift
index 862ece42..93cdeb3d 100644
--- a/ALCameraViewController/Views/CropOverlay.swift
+++ b/ALCameraViewController/Views/CropOverlay.swift
@@ -33,7 +33,7 @@ internal class CropOverlay: UIView {
var outterGap: CGFloat {
return self.cornerButtonWidth * self.outterGapRatio
}
-
+ var isSquarable: Bool = false
var isResizable: Bool = false
var isMovable: Bool = false
var minimumSize: CGSize = CGSize.zero
@@ -184,7 +184,10 @@ internal class CropOverlay: UIView {
newFrame = CGRect.zero
}
- let minimumFrame = CGRect(x: newFrame.origin.x, y: newFrame.origin.y, width: max(newFrame.size.width, minimumSize.width + 2 * outterGap), height: max(newFrame.size.height, minimumSize.height + 2 * outterGap))
+ var minimumFrame = CGRect(x: newFrame.origin.x, y: newFrame.origin.y, width: max(newFrame.size.width, minimumSize.width + 2 * outterGap), height: max(newFrame.size.height, minimumSize.height + 2 * outterGap))
+ if isSquarable {
+ minimumFrame = CGRect(x: newFrame.origin.x, y: newFrame.origin.y, width: max(minimumFrame.size.height, minimumFrame.size.width), height: max(minimumFrame.size.height, minimumFrame.size.width))
+ }
frame = minimumFrame
layoutSubviews()
diff --git a/Example/ViewController.swift b/Example/ViewController.swift
index e4c6aa1b..79820154 100644
--- a/Example/ViewController.swift
+++ b/Example/ViewController.swift
@@ -11,13 +11,13 @@ import UIKit
class ViewController: UIViewController {
var libraryEnabled: Bool = true
- var croppingEnabled: Bool = false
+ var croppingEnabled: Bool = true
var allowResizing: Bool = true
- var allowMoving: Bool = false
+ var allowMoving: Bool = true
var minimumSize: CGSize = CGSize(width: 60, height: 60)
var croppingParameters: CroppingParameters {
- return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, allowMoving: allowMoving, minimumSize: minimumSize)
+ return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, allowMoving: allowMoving,squarableCrop: true, minimumSize: minimumSize)
}
@IBOutlet weak var imageView: UIImageView!
From 72ed077227dbcf19ef26c8384b2a3d1b24e32032 Mon Sep 17 00:00:00 2001
From: Amr Abdel-Wahab
Date: Wed, 11 Sep 2019 14:40:25 +0200
Subject: [PATCH 2/3] handle if device is nil in case of simulator
---
ALCameraViewController/Views/CameraView.swift | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/ALCameraViewController/Views/CameraView.swift b/ALCameraViewController/Views/CameraView.swift
index b008924b..89a28a44 100644
--- a/ALCameraViewController/Views/CameraView.swift
+++ b/ALCameraViewController/Views/CameraView.swift
@@ -28,13 +28,14 @@ public class CameraView: UIView {
session.sessionPreset = AVCaptureSession.Preset.photo
device = cameraWithPosition(position: currentPosition)
- if let device = device , device.hasFlash {
- do {
- try device.lockForConfiguration()
- device.flashMode = .auto
- device.unlockForConfiguration()
- } catch _ {}
+ guard let device = device , device.hasFlash else {
+ return
}
+ do {
+ try device.lockForConfiguration()
+ device.flashMode = .auto
+ device.unlockForConfiguration()
+ } catch _ {}
let outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
From 9b5dfe8a48ea87abca15c13249ad37379b977c21 Mon Sep 17 00:00:00 2001
From: Amr Abdel-Wahab
Date: Tue, 29 Dec 2020 15:46:33 +0200
Subject: [PATCH 3/3] handle un handleded enum case
---
ALCameraViewController/Utilities/PhotoLibraryAuthorizer.swift | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ALCameraViewController/Utilities/PhotoLibraryAuthorizer.swift b/ALCameraViewController/Utilities/PhotoLibraryAuthorizer.swift
index 43b10d67..2dfdfa36 100644
--- a/ALCameraViewController/Utilities/PhotoLibraryAuthorizer.swift
+++ b/ALCameraViewController/Utilities/PhotoLibraryAuthorizer.swift
@@ -32,7 +32,7 @@ class PhotoLibraryAuthorizer {
case .notDetermined:
PHPhotoLibrary.requestAuthorization(handleAuthorization)
break
- case .authorized:
+ case .authorized, .limited:
DispatchQueue.main.async {
self.completion(nil)
}
@@ -41,7 +41,7 @@ class PhotoLibraryAuthorizer {
DispatchQueue.main.async {
self.onDeniedOrRestricted(completion: self.completion)
}
- break
+ default: break
}
}
}