Skip to content

Commit

Permalink
feat: add more custom crop shapes (#111)
Browse files Browse the repository at this point in the history
* add more crop mask types
* add a SwiftUI example
* update the README
  • Loading branch information
guoyingtao committed May 2, 2021
1 parent 2ca28d4 commit 380dd01
Show file tree
Hide file tree
Showing 52 changed files with 1,213 additions and 137 deletions.
10 changes: 5 additions & 5 deletions Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17126"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -111,9 +111,9 @@
<rect key="frame" x="0.0" y="0.0" width="148" height="33.5"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Crop Ellipse"/>
<state key="normal" title="Crop Shapes"/>
<connections>
<action selector="cropEllips:" destination="BYZ-38-t0r" eventType="touchUpInside" id="1gF-aV-jyo"/>
<action selector="cropShapes:" destination="BYZ-38-t0r" eventType="touchUpInside" id="1gF-aV-jyo"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="c0b-7Q-V2t" userLabel="Hide Rotation Dial">
Expand Down Expand Up @@ -163,7 +163,6 @@
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="305" id="Rnv-Qx-Cds"/>
<constraint firstAttribute="width" constant="306" id="UJg-Uh-w9g"/>
</constraints>
</stackView>
Expand All @@ -182,6 +181,7 @@
</constraints>
</view>
<connections>
<outlet property="cropShapesButton" destination="L8S-OJ-shA" id="f3i-4a-hfL"/>
<outlet property="croppedImageView" destination="pUS-Eo-0ui" id="bP8-d1-p2l"/>
</connections>
</viewController>
Expand Down
8 changes: 2 additions & 6 deletions Example/ImagePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ open class ImagePicker: NSObject {
}

alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

if UIDevice.current.userInterfaceIdiom == .pad {
alertController.popoverPresentationController?.sourceView = sourceView
alertController.popoverPresentationController?.sourceRect = sourceView.bounds
alertController.popoverPresentationController?.permittedArrowDirections = [.down, .up]
}

alertController.handlePopupInBigScreenIfNeeded(sourceView: sourceView, permittedArrowDirections: [.down, .up])

self.presentationController?.present(alertController, animated: true)
}
Expand Down
32 changes: 16 additions & 16 deletions Example/MantisExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
29948E0712D368F93A37FE3F /* Pods_MantisExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C752159CA735B6CD321D4DE /* Pods_MantisExampleTests.framework */; };
1F3B49FC588AD98287DE4267 /* libPods-MantisExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B8C6829EE0F5C72DC10C396B /* libPods-MantisExample.a */; };
5F0852B5237918510031B75D /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F0852B4237918510031B75D /* ImagePicker.swift */; };
5FC10B15217A9EDF00582874 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC10B14217A9EDF00582874 /* AppDelegate.swift */; };
5FC10B17217A9EDF00582874 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC10B16217A9EDF00582874 /* ViewController.swift */; };
Expand All @@ -17,8 +17,8 @@
5FC10B2A217A9EE100582874 /* MantisTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC10B29217A9EE100582874 /* MantisTests.swift */; };
5FD045EA245619D400B9D3D2 /* CustomizedCropToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FD045E9245619D400B9D3D2 /* CustomizedCropToolbar.swift */; };
5FEBA88221961E4A0018DE62 /* EmbeddedCropViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FEBA88121961E4A0018DE62 /* EmbeddedCropViewController.swift */; };
AF2FE35191AA9D90825785AE /* libPods-MantisExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 652EE158B8C4F04DF075F81D /* libPods-MantisExampleTests.a */; };
CCBF2F602525B3050081B8FE /* CustomizedCropToolbarWithoutList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCBF2F5F2525B3050081B8FE /* CustomizedCropToolbarWithoutList.swift */; };
E2492248DC39DB830291D12C /* Pods_MantisExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9EBBB1F17EF55BEB5F30AA7 /* Pods_MantisExample.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -50,27 +50,27 @@
5FD045E9245619D400B9D3D2 /* CustomizedCropToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomizedCropToolbar.swift; sourceTree = "<group>"; };
5FEBA88121961E4A0018DE62 /* EmbeddedCropViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedCropViewController.swift; sourceTree = "<group>"; };
61C386518C3C25E57F8C83A5 /* Pods-MantisExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MantisExampleTests.release.xcconfig"; path = "Target Support Files/Pods-MantisExampleTests/Pods-MantisExampleTests.release.xcconfig"; sourceTree = "<group>"; };
652EE158B8C4F04DF075F81D /* libPods-MantisExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MantisExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
89C5370690AB91AB238B90E9 /* Pods-MantisExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MantisExample.release.xcconfig"; path = "Target Support Files/Pods-MantisExample/Pods-MantisExample.release.xcconfig"; sourceTree = "<group>"; };
8C752159CA735B6CD321D4DE /* Pods_MantisExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MantisExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9326C1CDF121300C5CAAE2BE /* Pods-MantisExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MantisExample.debug.xcconfig"; path = "Target Support Files/Pods-MantisExample/Pods-MantisExample.debug.xcconfig"; sourceTree = "<group>"; };
B8C6829EE0F5C72DC10C396B /* libPods-MantisExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MantisExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
CCBF2F5F2525B3050081B8FE /* CustomizedCropToolbarWithoutList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomizedCropToolbarWithoutList.swift; sourceTree = "<group>"; };
D9EBBB1F17EF55BEB5F30AA7 /* Pods_MantisExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MantisExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
5FC10B0E217A9EDF00582874 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E2492248DC39DB830291D12C /* Pods_MantisExample.framework in Frameworks */,
1F3B49FC588AD98287DE4267 /* libPods-MantisExample.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5FC10B22217A9EE100582874 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
29948E0712D368F93A37FE3F /* Pods_MantisExampleTests.framework in Frameworks */,
AF2FE35191AA9D90825785AE /* libPods-MantisExampleTests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -80,8 +80,8 @@
5F3BE15921993A7C005C4BD8 /* Frameworks */ = {
isa = PBXGroup;
children = (
D9EBBB1F17EF55BEB5F30AA7 /* Pods_MantisExample.framework */,
8C752159CA735B6CD321D4DE /* Pods_MantisExampleTests.framework */,
B8C6829EE0F5C72DC10C396B /* libPods-MantisExample.a */,
652EE158B8C4F04DF075F81D /* libPods-MantisExampleTests.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -147,7 +147,7 @@
5FC10B0D217A9EDF00582874 /* Sources */,
5FC10B0E217A9EDF00582874 /* Frameworks */,
5FC10B0F217A9EDF00582874 /* Resources */,
29075393B588C1F5FC8365D7 /* [CP] Embed Pods Frameworks */,
12B88BB2DAEBCE3C6ACE78D7 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -261,21 +261,21 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
29075393B588C1F5FC8365D7 /* [CP] Embed Pods Frameworks */ = {
12B88BB2DAEBCE3C6ACE78D7 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-MantisExample/Pods-MantisExample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-MantisExample/Pods-MantisExample-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-MantisExample/Pods-MantisExample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-MantisExample/Pods-MantisExample-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MantisExample/Pods-MantisExample-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MantisExample/Pods-MantisExample-resources.sh\"\n";
showEnvVarsInLog = 0;
};
B990B0C0191568D739FE220D /* [CP] Check Pods Manifest.lock */ = {
Expand Down Expand Up @@ -482,7 +482,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = MantisExample.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
Expand All @@ -508,7 +508,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = MantisExample.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

target 'MantisExample' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
#use_frameworks!

# Pods for MantisExample
pod 'Mantis', :path => '../'
Expand Down

0 comments on commit 380dd01

Please sign in to comment.