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

Commit dca6387

Browse files
Allow ragging movement of overlay to be configured
1 parent d88b584 commit dca6387

File tree

7 files changed

+84
-46
lines changed

7 files changed

+84
-46
lines changed

ALCameraViewController.xcodeproj/project.pbxproj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
attributes = {
271271
LastSwiftMigration = 0700;
272272
LastSwiftUpdateCheck = 0700;
273-
LastUpgradeCheck = 0800;
273+
LastUpgradeCheck = 0900;
274274
ORGANIZATIONNAME = zero;
275275
TargetAttributes = {
276276
C4829FFA1CAEB16C00541D08 = {
@@ -279,7 +279,7 @@
279279
};
280280
FAF0583E1B31618D008E5592 = {
281281
CreatedOnToolsVersion = 6.3.2;
282-
DevelopmentTeam = GAPQH4AM76;
282+
DevelopmentTeam = 2466624KEK;
283283
LastSwiftMigration = 0800;
284284
ProvisioningStyle = Automatic;
285285
};
@@ -442,14 +442,20 @@
442442
CLANG_CXX_LIBRARY = "libc++";
443443
CLANG_ENABLE_MODULES = YES;
444444
CLANG_ENABLE_OBJC_ARC = YES;
445+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
445446
CLANG_WARN_BOOL_CONVERSION = YES;
447+
CLANG_WARN_COMMA = YES;
446448
CLANG_WARN_CONSTANT_CONVERSION = YES;
447449
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
448450
CLANG_WARN_EMPTY_BODY = YES;
449451
CLANG_WARN_ENUM_CONVERSION = YES;
450452
CLANG_WARN_INFINITE_RECURSION = YES;
451453
CLANG_WARN_INT_CONVERSION = YES;
454+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
455+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
452456
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
457+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
458+
CLANG_WARN_STRICT_PROTOTYPES = YES;
453459
CLANG_WARN_SUSPICIOUS_MOVE = YES;
454460
CLANG_WARN_UNREACHABLE_CODE = YES;
455461
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -490,14 +496,20 @@
490496
CLANG_CXX_LIBRARY = "libc++";
491497
CLANG_ENABLE_MODULES = YES;
492498
CLANG_ENABLE_OBJC_ARC = YES;
499+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
493500
CLANG_WARN_BOOL_CONVERSION = YES;
501+
CLANG_WARN_COMMA = YES;
494502
CLANG_WARN_CONSTANT_CONVERSION = YES;
495503
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
496504
CLANG_WARN_EMPTY_BODY = YES;
497505
CLANG_WARN_ENUM_CONVERSION = YES;
498506
CLANG_WARN_INFINITE_RECURSION = YES;
499507
CLANG_WARN_INT_CONVERSION = YES;
508+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
509+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
500510
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
511+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
512+
CLANG_WARN_STRICT_PROTOTYPES = YES;
501513
CLANG_WARN_SUSPICIOUS_MOVE = YES;
502514
CLANG_WARN_UNREACHABLE_CODE = YES;
503515
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -529,11 +541,11 @@
529541
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
530542
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
531543
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
532-
DEVELOPMENT_TEAM = GAPQH4AM76;
544+
DEVELOPMENT_TEAM = 2466624KEK;
533545
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
534546
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
535547
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
536-
PRODUCT_BUNDLE_IDENTIFIER = com.zero.CameraViewController;
548+
PRODUCT_BUNDLE_IDENTIFIER = com.alx2.zero.CameraViewController;
537549
PRODUCT_NAME = "$(TARGET_NAME)";
538550
SWIFT_VERSION = 3.0;
539551
};
@@ -545,11 +557,11 @@
545557
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
546558
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
547559
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
548-
DEVELOPMENT_TEAM = GAPQH4AM76;
560+
DEVELOPMENT_TEAM = 2466624KEK;
549561
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
550562
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
551563
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
552-
PRODUCT_BUNDLE_IDENTIFIER = com.zero.CameraViewController;
564+
PRODUCT_BUNDLE_IDENTIFIER = com.alx2.zero.CameraViewController;
553565
PRODUCT_NAME = "$(TARGET_NAME)";
554566
SWIFT_VERSION = 3.0;
555567
};

ALCameraViewController.xcodeproj/xcshareddata/xcschemes/CameraViewController.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -36,6 +37,7 @@
3637
buildConfiguration = "Debug"
3738
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3839
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
40+
language = ""
3941
launchStyle = "0"
4042
useCustomWorkingDirectory = "NO"
4143
ignoresPersistentStateOnLaunch = "NO"

ALCameraViewController/Utilities/CroppingParameters.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@ public struct CroppingParameters {
1818
/// Default value is set to true.
1919
var allowResizing: Bool
2020

21+
/// Allow the cropping area to be moved by the user.
22+
/// Default value is set to false.
23+
var allowMoving: Bool
24+
2125
/// Prevent the user to resize the cropping area below a minimum size.
2226
/// Default value is (60, 60). Below this value, corner buttons will overlap.
2327
var minimumSize: CGSize
2428

25-
init(isEnabled: Bool = false,
26-
allowResizing: Bool = true,
29+
public init(isEnabled: Bool = false,
30+
allowResizing: Bool = true,
31+
allowMoving: Bool = true,
2732
minimumSize: CGSize = CGSize(width: 60, height: 60)) {
2833

2934
self.isEnabled = isEnabled
3035
self.allowResizing = allowResizing
36+
self.allowMoving = allowMoving
3137
self.minimumSize = minimumSize
3238
}
3339
}

ALCameraViewController/ViewController/ConfirmViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
7070

7171
cropOverlay.isHidden = true
7272
cropOverlay.isResizable = croppingParameters.allowResizing
73+
cropOverlay.isMovable = croppingParameters.allowMoving
7374
cropOverlay.minimumSize = croppingParameters.minimumSize
7475

7576
let spinner = showSpinner()

ALCameraViewController/Views/CropOverlay.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal class CropOverlay: UIView {
3535
}
3636

3737
var isResizable: Bool = false
38+
var isMovable: Bool = false
3839
var minimumSize: CGSize = CGSize.zero
3940

4041
internal override init(frame: CGRect) {
@@ -158,21 +159,13 @@ internal class CropOverlay: UIView {
158159

159160
let dragGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(moveCropOverlay))
160161
button.addGestureRecognizer(dragGestureRecognizer)
161-
162-
// // DEBUG
163-
// button.backgroundColor = .yellow
164-
// button.alpha = 0.2
165162

166163
addSubview(button)
167164
return button
168165
}
169166

170167
func moveCropOverlay(gestureRecognizer: UIPanGestureRecognizer) {
171-
if let button = gestureRecognizer.view as? UIButton {
172-
guard isResizable else {
173-
return
174-
}
175-
168+
if isResizable, let button = gestureRecognizer.view as? UIButton {
176169
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
177170
let translation = gestureRecognizer.translation(in: self)
178171

@@ -197,7 +190,7 @@ internal class CropOverlay: UIView {
197190

198191
gestureRecognizer.setTranslation(CGPoint.zero, in: self)
199192
}
200-
} else {
193+
} else if isMovable {
201194
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
202195
let translation = gestureRecognizer.translation(in: self)
203196

Example/ViewController.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class ViewController: UIViewController {
1313
var libraryEnabled: Bool = true
1414
var croppingEnabled: Bool = false
1515
var allowResizing: Bool = true
16+
var allowMoving: Bool = false
1617
var minimumSize: CGSize = CGSize(width: 60, height: 60)
1718

1819
var croppingParameters: CroppingParameters {
19-
return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, minimumSize: minimumSize)
20+
return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, allowMoving: allowMoving, minimumSize: minimumSize)
2021
}
2122

2223
@IBOutlet weak var imageView: UIImageView!
@@ -51,32 +52,23 @@ class ViewController: UIViewController {
5152
libraryEnabled = !libraryEnabled
5253
}
5354

54-
@IBAction func croppingChanged(_ sender: Any) {
55-
guard let switchButton = sender as? UISwitch else {
56-
return
57-
}
58-
59-
croppingEnabled = switchButton.isOn
60-
croppingParametersView.isHidden = !switchButton.isOn
55+
@IBAction func croppingChanged(_ sender: UISwitch) {
56+
croppingEnabled = sender.isOn
57+
croppingParametersView.isHidden = !sender.isOn
6158
}
6259

63-
@IBAction func resizingChanged(_ sender: Any) {
64-
guard let switchButton = sender as? UISwitch else {
65-
return
66-
}
67-
68-
allowResizing = switchButton.isOn
60+
@IBAction func resizingChanged(_ sender: UISwitch) {
61+
allowResizing = sender.isOn
6962
}
7063

71-
@IBAction func minimumSizeChanged(_ sender: Any) {
72-
guard let sliderButton = sender as? UISlider else {
73-
return
74-
}
64+
@IBAction func movingChanged(_ sender: UISwitch) {
65+
allowMoving = sender.isOn
66+
}
7567

76-
let newValue = sliderButton.value
68+
@IBAction func minimumSizeChanged(_ sender: UISlider) {
69+
let newValue = sender.value
7770
minimumSize = CGSize(width: CGFloat(newValue), height: CGFloat(newValue))
7871
minimumSizeLabel.text = "Minimum size: \(newValue.rounded())"
7972
}
80-
8173
}
8274

Example/ViewController.xib

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13189.4" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
33
<device id="retina4_0" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13165.3"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
11+
<customFonts key="customFonts">
12+
<array key="AppleSDGothicNeo.ttc">
13+
<string>AppleSDGothicNeo-Regular</string>
14+
</array>
15+
</customFonts>
1116
<objects>
1217
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ViewController" customModule="ALCameraViewController" customModuleProvider="target">
1318
<connections>
@@ -91,17 +96,17 @@
9196
</constraints>
9297
</view>
9398
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aZk-39-lei">
94-
<rect key="frame" x="0.0" y="468" width="320" height="100"/>
99+
<rect key="frame" x="0.0" y="463" width="320" height="105"/>
95100
<subviews>
96101
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="k5h-ry-m8S">
97-
<rect key="frame" x="24" y="28" width="51" height="31"/>
102+
<rect key="frame" x="15" y="28" width="51" height="31"/>
98103
<connections>
99104
<action selector="libraryChanged:" destination="-1" eventType="valueChanged" id="LKB-0U-NRn"/>
100105
<action selector="resizingChanged:" destination="-1" eventType="valueChanged" id="veN-be-OGb"/>
101106
</connections>
102107
</switch>
103-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Allow resizing" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="In7-Or-H5s">
104-
<rect key="frame" x="8" y="65" width="81.5" height="17"/>
108+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="isResizable" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="In7-Or-H5s">
109+
<rect key="frame" x="8" y="65" width="64" height="17"/>
105110
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Regular" family="Apple SD Gothic Neo" pointSize="14"/>
106111
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
107112
<nil key="highlightedColor"/>
@@ -121,17 +126,44 @@
121126
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
122127
<nil key="highlightedColor"/>
123128
</label>
129+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DSI-Wk-w93">
130+
<rect key="frame" x="96" y="28" width="51" height="31"/>
131+
<connections>
132+
<action selector="libraryChanged:" destination="-1" eventType="valueChanged" id="wgu-jE-pwk"/>
133+
<action selector="movingChanged:" destination="-1" eventType="valueChanged" id="VNQ-EU-Pcc"/>
134+
<action selector="resizingChanged:" destination="-1" eventType="valueChanged" id="dWI-k0-WsG"/>
135+
</connections>
136+
</switch>
137+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="isMovable" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YNR-ru-Naw">
138+
<rect key="frame" x="91" y="65" width="59" height="17"/>
139+
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Regular" family="Apple SD Gothic Neo" pointSize="14"/>
140+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
141+
<nil key="highlightedColor"/>
142+
</label>
143+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Crop settings:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cSR-t6-yJv">
144+
<rect key="frame" x="8" y="8" width="82" height="12"/>
145+
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Regular" family="Apple SD Gothic Neo" pointSize="14"/>
146+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
147+
<nil key="highlightedColor"/>
148+
</label>
124149
</subviews>
125150
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.29999999999999999" colorSpace="custom" customColorSpace="sRGB"/>
126151
<constraints>
152+
<constraint firstItem="DSI-Wk-w93" firstAttribute="leading" secondItem="k5h-ry-m8S" secondAttribute="trailing" constant="32" id="2Sk-tz-Ope"/>
153+
<constraint firstItem="k5h-ry-m8S" firstAttribute="top" secondItem="cSR-t6-yJv" secondAttribute="bottom" constant="8" id="Fb1-4H-MtS"/>
154+
<constraint firstItem="DSI-Wk-w93" firstAttribute="centerY" secondItem="k5h-ry-m8S" secondAttribute="centerY" id="GXP-Jm-a8F"/>
127155
<constraint firstItem="DXi-q2-e5s" firstAttribute="top" secondItem="wMe-QX-l9A" secondAttribute="bottom" constant="6" id="JKt-OZ-OfS"/>
128-
<constraint firstAttribute="height" constant="100" id="MTP-Zi-Sp6"/>
156+
<constraint firstAttribute="height" constant="105" id="MTP-Zi-Sp6"/>
129157
<constraint firstItem="wMe-QX-l9A" firstAttribute="top" secondItem="k5h-ry-m8S" secondAttribute="top" id="Oi9-A3-OeO"/>
130158
<constraint firstItem="k5h-ry-m8S" firstAttribute="top" secondItem="aZk-39-lei" secondAttribute="top" constant="28" id="YVP-87-gmz"/>
159+
<constraint firstItem="cSR-t6-yJv" firstAttribute="leading" secondItem="aZk-39-lei" secondAttribute="leading" constant="8" id="bIT-h5-U4i"/>
160+
<constraint firstItem="YNR-ru-Naw" firstAttribute="centerX" secondItem="DSI-Wk-w93" secondAttribute="centerX" id="lcN-lZ-MWU"/>
161+
<constraint firstItem="cSR-t6-yJv" firstAttribute="top" secondItem="aZk-39-lei" secondAttribute="top" constant="8" id="nWf-SV-5lr"/>
131162
<constraint firstAttribute="trailing" secondItem="wMe-QX-l9A" secondAttribute="trailing" constant="8" id="oW4-sC-slS"/>
132163
<constraint firstItem="In7-Or-H5s" firstAttribute="top" secondItem="k5h-ry-m8S" secondAttribute="bottom" constant="6" id="op5-Pa-JNB"/>
133164
<constraint firstItem="DXi-q2-e5s" firstAttribute="centerX" secondItem="wMe-QX-l9A" secondAttribute="centerX" id="usT-6x-EtL"/>
134165
<constraint firstItem="In7-Or-H5s" firstAttribute="leading" secondItem="aZk-39-lei" secondAttribute="leading" constant="8" id="wRs-Qw-Sic"/>
166+
<constraint firstItem="YNR-ru-Naw" firstAttribute="top" secondItem="DSI-Wk-w93" secondAttribute="bottom" constant="6" id="y3p-bV-bPy"/>
135167
<constraint firstItem="k5h-ry-m8S" firstAttribute="centerX" secondItem="In7-Or-H5s" secondAttribute="centerX" id="z4S-xt-ZNI"/>
136168
</constraints>
137169
</view>

0 commit comments

Comments
 (0)