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/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexLittlejohn committed Sep 4, 2017
2 parents 8dccb17 + df98b19 commit 7b9c516
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 130 deletions.
2 changes: 1 addition & 1 deletion ALCameraViewController.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "ALCameraViewController"
spec.version = "1.4.1"
spec.version = "2.0.0"
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
Expand Down
18 changes: 17 additions & 1 deletion ALCameraViewController.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
7AC96FA21F5B5166003E53F4 /* CroppingParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AC96FA11F5B5166003E53F4 /* CroppingParameters.swift */; };
C40665441C73A47C00EB9751 /* SingleImageSaver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40665431C73A47C00EB9751 /* SingleImageSaver.swift */; };
C40665461C73A94100EB9751 /* CameraGlobals.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40665451C73A94100EB9751 /* CameraGlobals.swift */; };
C40665481C73B72D00EB9751 /* SingleImageFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40665471C73B72D00EB9751 /* SingleImageFetcher.swift */; };
Expand Down Expand Up @@ -58,6 +59,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7AC96FA11F5B5166003E53F4 /* CroppingParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CroppingParameters.swift; sourceTree = "<group>"; };
C40665431C73A47C00EB9751 /* SingleImageSaver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleImageSaver.swift; sourceTree = "<group>"; };
C40665451C73A94100EB9751 /* CameraGlobals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraGlobals.swift; sourceTree = "<group>"; };
C40665471C73B72D00EB9751 /* SingleImageFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleImageFetcher.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,6 +156,7 @@
C4D9BA441CA7224B004F70F7 /* PhotoLibraryAuthorizer.swift */,
C4D9BA461CA73163004F70F7 /* UIButtonExtensions.swift */,
EBFE097C1CAF1D1A00A8C637 /* UIViewExtensions.swift */,
7AC96FA11F5B5166003E53F4 /* CroppingParameters.swift */,
);
path = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -267,7 +270,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = zero;
TargetAttributes = {
C4829FFA1CAEB16C00541D08 = {
Expand Down Expand Up @@ -366,6 +369,7 @@
FAB50C001B413E8C009905B9 /* PhotoLibraryViewController.swift in Sources */,
FAF0586A1B317894008E5592 /* CameraShot.swift in Sources */,
FAF058661B316695008E5592 /* CameraViewController.swift in Sources */,
7AC96FA21F5B5166003E53F4 /* CroppingParameters.swift in Sources */,
C4D9BA451CA7224B004F70F7 /* PhotoLibraryAuthorizer.swift in Sources */,
FAB50BFB1B413E8C009905B9 /* ImageCell.swift in Sources */,
EBFE097D1CAF1D1A00A8C637 /* UIViewExtensions.swift in Sources */,
Expand Down Expand Up @@ -438,14 +442,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -486,14 +496,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
39 changes: 39 additions & 0 deletions ALCameraViewController/Utilities/CroppingParameters.swift
@@ -0,0 +1,39 @@
//
// CroppingParameters.swift
// ALCameraViewController
//
// Created by Guillaume Bellut on 02/09/2017.
// Copyright © 2017 zero. All rights reserved.
//

import UIKit

public struct CroppingParameters {

/// Enable the cropping feature.
/// Default value is set to false.
var isEnabled: Bool

/// Allow the cropping area to be resized by the user.
/// Default value is set to true.
var allowResizing: Bool

/// Allow the cropping area to be moved by the user.
/// Default value is set to false.
var allowMoving: 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.
var minimumSize: CGSize

public init(isEnabled: Bool = false,
allowResizing: Bool = true,
allowMoving: Bool = true,
minimumSize: CGSize = CGSize(width: 60, height: 60)) {

self.isEnabled = isEnabled
self.allowResizing = allowResizing
self.allowMoving = allowMoving
self.minimumSize = minimumSize
}
}
9 changes: 4 additions & 5 deletions ALCameraViewController/Utilities/SingleImageFetcher.swift
Expand Up @@ -78,12 +78,11 @@ public class SingleImageFetcher {
options.resizeMode = .exact

let targetWidth = floor(CGFloat(asset.pixelWidth) * cropRect.width)
let targetHeight = floor(CGFloat(asset.pixelHeight) * cropRect.height)
let dimension = max(min(targetHeight, targetWidth), 1024 * scale)

targetSize = CGSize(width: dimension, height: dimension)
let targetHeight = floor(CGFloat(asset.pixelHeight) * cropRect.height)

targetSize = CGSize(width: targetWidth, height: targetHeight)
}
PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFill, options: options) { image, _ in
if let image = image {
self.success?(image)
Expand Down
27 changes: 16 additions & 11 deletions ALCameraViewController/ViewController/CameraViewController.swift
Expand Up @@ -14,7 +14,7 @@ public typealias CameraViewCompletion = (UIImage?, PHAsset?) -> Void

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

Expand All @@ -24,7 +24,7 @@ public extension CameraViewController {

imagePicker.onSelectionComplete = { [weak imagePicker] asset in
if let asset = asset {
let confirmController = ConfirmViewController(asset: asset, allowsCropping: croppingEnabled)
let confirmController = ConfirmViewController(asset: asset, croppingParameters: croppingParameters)
confirmController.onComplete = { [weak imagePicker] image, asset in
if let image = image, let asset = asset {
completion(image, asset)
Expand All @@ -46,7 +46,7 @@ public extension CameraViewController {
open class CameraViewController: UIViewController {

var didUpdateViews = false
var allowCropping = false
var croppingParameters: CroppingParameters
var animationRunning = false
let allowVolumeButtonCapture: Bool

Expand Down Expand Up @@ -89,7 +89,7 @@ open class CameraViewController: UIViewController {
cameraView.translatesAutoresizingMaskIntoConstraints = false
return cameraView
}()

let cameraOverlay : CropOverlay = {
let cameraOverlay = CropOverlay()
cameraOverlay.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -159,13 +159,18 @@ open class CameraViewController: UIViewController {

private let allowsLibraryAccess: Bool

public init(croppingEnabled: Bool, allowsLibraryAccess: Bool = true, allowsSwapCameraOrientation: Bool = true, allowVolumeButtonCapture: Bool = true, completion: @escaping CameraViewCompletion) {
self.allowsLibraryAccess = allowsLibraryAccess
public init(croppingParameters: CroppingParameters = CroppingParameters(),
allowsLibraryAccess: Bool = true,
allowsSwapCameraOrientation: Bool = true,
allowVolumeButtonCapture: Bool = true,
completion: @escaping CameraViewCompletion) {

self.croppingParameters = croppingParameters
self.allowsLibraryAccess = allowsLibraryAccess
self.allowVolumeButtonCapture = allowVolumeButtonCapture
super.init(nibName: nil, bundle: nil)
onCompletion = completion
allowCropping = croppingEnabled
cameraOverlay.isHidden = !allowCropping
cameraOverlay.isHidden = !croppingParameters.isEnabled
libraryButton.isEnabled = allowsLibraryAccess
libraryButton.isHidden = !allowsLibraryAccess
swapButton.isEnabled = allowsSwapCameraOrientation
Expand Down Expand Up @@ -539,7 +544,7 @@ open class CameraViewController: UIViewController {
}

internal func showLibrary() {
let imagePicker = CameraViewController.imagePickerViewController(croppingEnabled: allowCropping) { [weak self] image, asset in
let imagePicker = CameraViewController.imagePickerViewController(croppingParameters: croppingParameters) { [weak self] image, asset in
defer {
self?.dismiss(animated: true, completion: nil)
}
Expand Down Expand Up @@ -588,7 +593,7 @@ open class CameraViewController: UIViewController {
}

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

private func startConfirmController(asset: PHAsset) {
let confirmViewController = ConfirmViewController(asset: asset, allowsCropping: allowCropping)
let confirmViewController = ConfirmViewController(asset: asset, croppingParameters: croppingParameters)
confirmViewController.onComplete = { [weak self] image, asset in
defer {
self?.dismiss(animated: true, completion: nil)
Expand Down

0 comments on commit 7b9c516

Please sign in to comment.