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/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 } } } 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/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] 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!