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

Commit

Permalink
allow Square Crop
Browse files Browse the repository at this point in the history
  • Loading branch information
Orcas Development committed Apr 2, 2019
1 parent 74835ed commit 18f5bf2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ALCameraViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
};
FAF0583E1B31618D008E5592 = {
CreatedOnToolsVersion = 6.3.2;
DevelopmentTeam = 2466624KEK;
DevelopmentTeam = FX2Z63PGT5;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
4 changes: 4 additions & 0 deletions ALCameraViewController/Utilities/CroppingParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions ALCameraViewController/Views/CropOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

1 comment on commit 18f5bf2

@RiteshParyali
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it isworking

Please sign in to comment.