Skip to content

Commit

Permalink
feat: Open up CropViewController for inheritance. (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Feb 5, 2023
1 parent 068c49f commit cdeafcd
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 26 deletions.
43 changes: 26 additions & 17 deletions Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fpr-TJ-i7J">
<rect key="frame" x="0.0" y="0.0" width="306" height="34"/>
<rect key="frame" x="0.0" y="0.0" width="306" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Select from Album"/>
Expand All @@ -31,10 +31,10 @@
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="0o0-4T-StV">
<rect key="frame" x="0.0" y="38" width="306" height="33.5"/>
<rect key="frame" x="0.0" y="33" width="306" height="29.5"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Sau-lB-dow">
<rect key="frame" x="0.0" y="0.0" width="95.5" height="33.5"/>
<rect key="frame" x="0.0" y="0.0" width="95.5" height="29.5"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Normal"/>
Expand All @@ -43,7 +43,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PY0-hE-TGk">
<rect key="frame" x="105.5" y="0.0" width="95" height="33.5"/>
<rect key="frame" x="105.5" y="0.0" width="95" height="29.5"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Embedded"/>
Expand All @@ -52,7 +52,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="A41-u7-U97">
<rect key="frame" x="210.5" y="0.0" width="95.5" height="33.5"/>
<rect key="frame" x="210.5" y="0.0" width="95.5" height="29.5"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Transformation"/>
Expand All @@ -63,7 +63,7 @@
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dgZ-jD-v0j">
<rect key="frame" x="0.0" y="75.5" width="306" height="34"/>
<rect key="frame" x="0.0" y="66.5" width="306" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="AlwaysUseOnePresetRatio"/>
Expand All @@ -72,11 +72,20 @@
<action selector="normalPresent:" destination="BYZ-38-t0r" eventType="touchUpInside" id="N2U-ea-YZw"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6JW-Rf-Zds">
<rect key="frame" x="0.0" y="99.5" width="306" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Custom View Controller"/>
<connections>
<action selector="customViewController:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Kne-tp-yHY"/>
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="12F-q3-2Fl">
<rect key="frame" x="0.0" y="113.5" width="306" height="34"/>
<rect key="frame" x="0.0" y="132.5" width="306" height="29"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lQp-Zn-dI8" userLabel="Custom CropToolbar">
<rect key="frame" x="0.0" y="0.0" width="148" height="34"/>
<rect key="frame" x="0.0" y="0.0" width="148" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Custom Toolbar (List)"/>
Expand All @@ -85,7 +94,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GXf-4G-I8W">
<rect key="frame" x="158" y="0.0" width="148" height="34"/>
<rect key="frame" x="158" y="0.0" width="148" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Custom Toolbar (Buttons)"/>
Expand All @@ -96,7 +105,7 @@
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" verticalCompressionResistancePriority="749" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="d2a-Mk-kD7">
<rect key="frame" x="0.0" y="151.5" width="306" height="34"/>
<rect key="frame" x="0.0" y="165.5" width="306" height="29.5"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Clockwise roation"/>
Expand All @@ -105,10 +114,10 @@
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="oNS-aX-GCH">
<rect key="frame" x="0.0" y="189.5" width="306" height="33.5"/>
<rect key="frame" x="0.0" y="199" width="306" height="29"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="L8S-OJ-shA">
<rect key="frame" x="0.0" y="0.0" width="148" height="33.5"/>
<rect key="frame" x="0.0" y="0.0" width="148" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Crop Shapes"/>
Expand All @@ -117,7 +126,7 @@
</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">
<rect key="frame" x="158" y="0.0" width="148" height="33.5"/>
<rect key="frame" x="158" y="0.0" width="148" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Hide Rotation Dial"/>
Expand All @@ -128,10 +137,10 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="bu4-cG-VOh">
<rect key="frame" x="0.0" y="227" width="306" height="34"/>
<rect key="frame" x="0.0" y="232" width="306" height="29"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9WR-aF-zl2">
<rect key="frame" x="0.0" y="0.0" width="98.5" height="34"/>
<rect key="frame" x="0.0" y="0.0" width="98.5" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Dark Background"/>
Expand All @@ -141,7 +150,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FmB-6O-5mY">
<rect key="frame" x="103.5" y="0.0" width="99" height="34"/>
<rect key="frame" x="103.5" y="0.0" width="99" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="Light Background"/>
Expand All @@ -151,7 +160,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iaH-5e-UFH">
<rect key="frame" x="207.5" y="0.0" width="98.5" height="34"/>
<rect key="frame" x="207.5" y="0.0" width="98.5" height="29"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<state key="normal" title="No Background"/>
Expand Down
45 changes: 45 additions & 0 deletions Example/CustomViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// ViewController.swift
// Mantis
//
// Created by Yingtao Guo on 10/19/18.
// Copyright © 2018 Echo Studio. All rights reserved.
//

import UIKit
import Mantis

class CustomViewController: CropViewController {
override func viewDidLoad() {
super.viewDidLoad()

title = "Custom View Controller"

let rotate = UIBarButtonItem(
image: UIImage.init(systemName: "crop.rotate"),
style: .plain,
target: self,
action: #selector(onRotateClicked)
)

let done = UIBarButtonItem(
image: UIImage.init(systemName: "checkmark"),
style: .plain,
target: self,
action: #selector(onDoneClicked)
)

navigationItem.rightBarButtonItems = [
done,
rotate,
]
}

@objc private func onRotateClicked() {
didSelectClockwiseRotate()
}

@objc private func onDoneClicked() {
crop()
}
}
2 changes: 1 addition & 1 deletion Example/EmbeddedCropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EmbeddedCropViewController: UIViewController {
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let cropViewController = segue.destination as? CropViewController, let image else {
guard let cropViewController = segue.destination as? CropViewController, let image = image else {
return
}

Expand Down

0 comments on commit cdeafcd

Please sign in to comment.