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

Commit 18f5bf2

Browse files
author
Orcas Development
committed
allow Square Crop
1 parent 74835ed commit 18f5bf2

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

ALCameraViewController.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
};
284284
FAF0583E1B31618D008E5592 = {
285285
CreatedOnToolsVersion = 6.3.2;
286-
DevelopmentTeam = 2466624KEK;
286+
DevelopmentTeam = FX2Z63PGT5;
287287
LastSwiftMigration = 0900;
288288
ProvisioningStyle = Automatic;
289289
};
@@ -548,7 +548,7 @@
548548
buildSettings = {
549549
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
550550
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
551-
DEVELOPMENT_TEAM = 2466624KEK;
551+
DEVELOPMENT_TEAM = FX2Z63PGT5;
552552
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
553553
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
554554
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -564,7 +564,7 @@
564564
buildSettings = {
565565
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
566566
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
567-
DEVELOPMENT_TEAM = 2466624KEK;
567+
DEVELOPMENT_TEAM = FX2Z63PGT5;
568568
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
569569
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
570570
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

ALCameraViewController/Utilities/CroppingParameters.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public struct CroppingParameters {
2121
/// Allow the cropping area to be moved by the user.
2222
/// Default value is set to false.
2323
var allowMoving: Bool
24+
25+
var squarableCrop: Bool
2426

2527
/// Prevent the user to resize the cropping area below a minimum size.
2628
/// Default value is (60, 60). Below this value, corner buttons will overlap.
@@ -29,11 +31,13 @@ public struct CroppingParameters {
2931
public init(isEnabled: Bool = false,
3032
allowResizing: Bool = true,
3133
allowMoving: Bool = true,
34+
squarableCrop: Bool = true,
3235
minimumSize: CGSize = CGSize(width: 60, height: 60)) {
3336

3437
self.isEnabled = isEnabled
3538
self.allowResizing = allowResizing
3639
self.allowMoving = allowMoving
3740
self.minimumSize = minimumSize
41+
self.squarableCrop = squarableCrop
3842
}
3943
}

ALCameraViewController/ViewController/ConfirmViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
2020

2121
var croppingParameters: CroppingParameters {
2222
didSet {
23+
cropOverlay.isSquarable = croppingParameters.squarableCrop
2324
cropOverlay.isResizable = croppingParameters.allowResizing
2425
cropOverlay.minimumSize = croppingParameters.minimumSize
2526
}
@@ -71,6 +72,7 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
7172
cropOverlay.isHidden = true
7273
cropOverlay.isResizable = croppingParameters.allowResizing
7374
cropOverlay.isMovable = croppingParameters.allowMoving
75+
cropOverlay.isSquarable = croppingParameters.squarableCrop
7476
cropOverlay.minimumSize = croppingParameters.minimumSize
7577

7678
let spinner = showSpinner()

ALCameraViewController/Views/CropOverlay.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal class CropOverlay: UIView {
3333
var outterGap: CGFloat {
3434
return self.cornerButtonWidth * self.outterGapRatio
3535
}
36-
36+
var isSquarable: Bool = false
3737
var isResizable: Bool = false
3838
var isMovable: Bool = false
3939
var minimumSize: CGSize = CGSize.zero
@@ -184,7 +184,10 @@ internal class CropOverlay: UIView {
184184
newFrame = CGRect.zero
185185
}
186186

187-
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))
187+
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))
188+
if isSquarable {
189+
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))
190+
}
188191
frame = minimumFrame
189192
layoutSubviews()
190193

Example/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import UIKit
1111
class ViewController: UIViewController {
1212

1313
var libraryEnabled: Bool = true
14-
var croppingEnabled: Bool = false
14+
var croppingEnabled: Bool = true
1515
var allowResizing: Bool = true
16-
var allowMoving: Bool = false
16+
var allowMoving: Bool = true
1717
var minimumSize: CGSize = CGSize(width: 60, height: 60)
1818

1919
var croppingParameters: CroppingParameters {
20-
return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, allowMoving: allowMoving, minimumSize: minimumSize)
20+
return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, allowMoving: allowMoving,squarableCrop: true, minimumSize: minimumSize)
2121
}
2222

2323
@IBOutlet weak var imageView: UIImageView!

0 commit comments

Comments
 (0)