Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Temporary patch] Add a parameter to choose cropping square or not. #50

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions Sources/Demo/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="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Xv6-Ye-Vql">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Xv6-Ye-Vql">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -236,24 +236,31 @@
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="vwj-E5-JQy">
<rect key="frame" x="143" y="415" width="89" height="106"/>
<rect key="frame" x="103" y="415" width="169" height="144"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yql-ja-UAV">
<rect key="frame" x="0.0" y="0.0" width="89" height="30"/>
<state key="normal" title="Select Image"/>
<rect key="frame" x="0.0" y="0.0" width="169" height="30"/>
<state key="normal" title="Select Image(Square)"/>
<connections>
<action selector="didTapSquarePushButton:" destination="ra8-Bb-A3k" eventType="touchUpInside" id="i2F-Yt-Khk"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nvO-mR-uDW">
<rect key="frame" x="0.0" y="38" width="169" height="30"/>
<state key="normal" title="Select Image(Rectangle)"/>
<connections>
<action selector="didTapPushButton:" destination="ra8-Bb-A3k" eventType="touchUpInside" id="hKV-Zl-PgD"/>
<action selector="didTapRectanglePushButton:" destination="ra8-Bb-A3k" eventType="touchUpInside" id="3GJ-QU-L09"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Syo-y4-U1n" userLabel="Push (Keep)">
<rect key="frame" x="0.0" y="38" width="89" height="30"/>
<rect key="frame" x="0.0" y="76" width="169" height="30"/>
<state key="normal" title="Push (Keep)"/>
<connections>
<action selector="didTapPushKeepingButton:" destination="ra8-Bb-A3k" eventType="touchUpInside" id="FZj-LT-phc"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5OI-XE-CkV">
<rect key="frame" x="0.0" y="76" width="89" height="30"/>
<rect key="frame" x="0.0" y="114" width="169" height="30"/>
<state key="normal" title="Present"/>
<connections>
<action selector="didTapPresentButton" destination="ra8-Bb-A3k" eventType="touchUpInside" id="0JH-4b-s5l"/>
Expand All @@ -279,7 +286,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="QNl-KZ-Av6" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1334" y="-806"/>
<point key="canvasLocation" x="1535" y="-906"/>
</scene>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
Expand Down Expand Up @@ -558,7 +565,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="xMH-ix-B2p" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1975" y="-805"/>
<point key="canvasLocation" x="3140" y="-1052"/>
</scene>
<!--Asset Download Editor View Controller-->
<scene sceneID="3K0-as-67l">
Expand Down Expand Up @@ -612,7 +619,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="EYv-ag-Kyq" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1334" y="-1495"/>
<point key="canvasLocation" x="1489" y="-1697"/>
</scene>
</scenes>
</document>
45 changes: 37 additions & 8 deletions Sources/Demo/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import PixelEditor
final class EditorViewController : UIViewController {

@IBOutlet weak var imageView: UIImageView!

private var usesSquare = true

private lazy var stack = SquareEditingStack.init(
source: StaticImageSource(source: UIImage(named: "large")!),
Expand All @@ -48,14 +50,28 @@ final class EditorViewController : UIViewController {
present(nav, animated: true, completion: nil)
}

@IBAction func didTapPushButton(_ sender: Any) {
@IBAction func didTapSquarePushButton(_ sender: Any) {

let picker = UIImagePickerController()
picker.allowsEditing = false
picker.delegate = self
picker.sourceType = .photoLibrary

present(picker, animated: true, completion: nil)

usesSquare = true
}

@IBAction func didTapRectanglePushButton(_ sender: Any) {

let picker = UIImagePickerController()
picker.allowsEditing = false
picker.delegate = self
picker.sourceType = .photoLibrary

present(picker, animated: true, completion: nil)

usesSquare = false
}

@IBAction func didTapPushKeepingButton(_ sender: Any) {
Expand All @@ -79,14 +95,27 @@ extension EditorViewController : UIImagePickerControllerDelegate, UINavigationCo
let image = info[.originalImage] as! UIImage

picker.dismiss(animated: true, completion: nil)

let controller = PixelEditViewController.init(
image: image
)

controller.delegate = self

navigationController?.pushViewController(controller, animated: true)
if usesSquare {

let controller = PixelEditViewController.init(
image: image
)

controller.delegate = self

navigationController?.pushViewController(controller, animated: true)

} else {

let controller = PixelEditViewController(image: image, usesSquareCropping: false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This


controller.delegate = self

navigationController?.pushViewController(controller, animated: true)


}

}
}
Expand Down
38 changes: 32 additions & 6 deletions Sources/PixelEditor/PixelEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public final class PixelEditViewController : UIViewController {
self.editingStack.delegate = self
}
}

/// - TODO: this flag won't be used when specified EditingStack outside.
private var usesSquareCropping: Bool

// MARK: - Private Propaties

Expand Down Expand Up @@ -183,23 +186,36 @@ public final class PixelEditViewController : UIViewController {
image: UIImage,
doneButtonTitle: String = L10n.done,
colorCubeStorage: ColorCubeStorage = .default,
usesSquareCropping: Bool = true,
options: Options = .current
) {

let source = StaticImageSource(source: image)
self.init(source: source, colorCubeStorage: colorCubeStorage, options: options)

self.init(
source: source,
colorCubeStorage: colorCubeStorage,
usesSquareCropping: usesSquareCropping,
options: options
)

}

public init(
source: ImageSourceType,
doneButtonTitle: String = L10n.done,
colorCubeStorage: ColorCubeStorage = .default,
usesSquareCropping: Bool = true,
options: Options = .current
) {

self.imageSource = source
self.options = options
self.colorCubeStorage = colorCubeStorage
self.doneButtonTitle = doneButtonTitle
self.usesSquareCropping = usesSquareCropping
super.init(nibName: nil, bundle: nil)

}

@available(*, unavailable)
Expand All @@ -217,11 +233,21 @@ public final class PixelEditViewController : UIViewController {
root: do {

if editingStack == nil {
editingStack = SquareEditingStack.init(
source: imageSource,
previewSize: CGSize(width: view.bounds.width, height: view.bounds.width),
colorCubeStorage: colorCubeStorage
)

if usesSquareCropping {
editingStack = SquareEditingStack.init(
source: imageSource,
previewSize: CGSize(width: view.bounds.width, height: view.bounds.width),
colorCubeStorage: colorCubeStorage
)
} else {
editingStack = EditingStack.init(
source: imageSource,
previewSize: CGSize(width: view.bounds.width, height: view.bounds.width),
colorCubeStorage: colorCubeStorage
)
}

}
view.backgroundColor = .white

Expand Down