refactor example with pan gestures

to use view tags to sort outlet array
This commit is contained in:
Paul Zabelin
2019-03-20 10:47:08 -07:00
parent 3c9704c8a5
commit 71f08a0300
2 changed files with 38 additions and 48 deletions

View File

@@ -26,9 +26,7 @@ class PanViewController: UIViewController {
// MARK: - Outlets
@IBOutlet var cornerViews: [UIView]!
@IBOutlet weak var transView: UIView!
@IBOutlet weak var startView: UIView!
@IBOutlet weak var destView: UIView!
@IBOutlet weak var toBeTransformedView: UIView!
// MARK: - UIViewController
@@ -46,7 +44,7 @@ class PanViewController: UIViewController {
// MARK: - private
private func updatePosition() {
transView.layer.transform = transformToCorners()
toBeTransformedView.layer.transform = transformToCorners()
}
private func transformToCorners() -> CATransform3D {
@@ -56,11 +54,11 @@ class PanViewController: UIViewController {
private lazy var start: Perspective = createStartingPerspective()
private func createStartingPerspective() -> Perspective {
transView.resetAnchorPoint()
return Perspective(transView.frame)
toBeTransformedView.resetAnchorPoint()
return Perspective(toBeTransformedView.frame)
}
private var destination: Perspective {
return .init(cornerViews.map {$0.center})
return .init(cornerViews.sorted {$0.tag < $1.tag}.map {$0.center})
}
}

View File

@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="GDb-qn-IKv">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="GDb-qn-IKv">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -22,49 +21,20 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5Fh-mb-69Y">
<rect key="frame" x="0.0" y="0.0" width="152" height="122"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="1" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="l9I-OJ-n6G">
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="l9I-OJ-n6G" userLabel="Destination View">
<rect key="frame" x="100" y="100" width="200" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.58980089430000004" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="6jA-cO-kHv">
<rect key="frame" x="0.0" y="0.0" width="152" height="122"/>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" indicatorStyle="black" bouncesZoom="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="6jA-cO-kHv" userLabel="Transforming View">
<rect key="frame" x="0.0" y="0.0" width="200" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="0.49914925230061352" colorSpace="custom" customColorSpace="sRGB"/>
<string key="text">Drag corners of this view to change it's perspective in 3D. Notice you can still scroll the text within this scroll view. This indicates that view was really transformed in 3D and can be interacted using the 3D projection.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle0"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qnW-dm-dKZ" userLabel="4th corner">
<rect key="frame" x="85" y="285" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outletCollection property="gestureRecognizers" destination="yoO-wr-VEh" appends="YES" id="G90-ai-Ba1"/>
</connections>
</view>
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GXd-f4-Tva" userLabel="2nd corner">
<rect key="frame" x="285" y="85" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outletCollection property="gestureRecognizers" destination="KB0-gW-LkZ" appends="YES" id="2hu-35-W9v"/>
</connections>
</view>
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RAU-xU-nUy" userLabel="3rd corner">
<rect key="frame" x="285" y="285" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outletCollection property="gestureRecognizers" destination="Zcm-B9-Aqa" appends="YES" id="u9h-Ay-6Mw"/>
</connections>
</view>
<view alpha="0.5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kYW-iW-GWA" userLabel="1st corner">
<view alpha="0.5" tag="1" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kYW-iW-GWA" userLabel="1st corner">
<rect key="frame" x="85" y="85" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@@ -73,14 +43,36 @@
<outletCollection property="gestureRecognizers" destination="Dg0-Qp-y8w" appends="YES" id="WaO-BJ-hO2"/>
</connections>
</view>
<view alpha="0.5" tag="2" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GXd-f4-Tva" userLabel="2nd corner">
<rect key="frame" x="285" y="85" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outletCollection property="gestureRecognizers" destination="KB0-gW-LkZ" appends="YES" id="2hu-35-W9v"/>
</connections>
</view>
<view alpha="0.5" tag="3" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qnW-dm-dKZ" userLabel="3rd corner">
<rect key="frame" x="85" y="285" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outletCollection property="gestureRecognizers" destination="yoO-wr-VEh" appends="YES" id="G90-ai-Ba1"/>
</connections>
</view>
<view alpha="0.5" tag="4" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RAU-xU-nUy" userLabel="4th corner">
<rect key="frame" x="285" y="285" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outletCollection property="gestureRecognizers" destination="Zcm-B9-Aqa" appends="YES" id="u9h-Ay-6Mw"/>
</connections>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<tabBarItem key="tabBarItem" systemItem="featured" id="heT-hQ-d7k"/>
<connections>
<outlet property="destView" destination="l9I-OJ-n6G" id="gcy-eY-ymS"/>
<outlet property="startView" destination="5Fh-mb-69Y" id="ahd-MV-6i4"/>
<outlet property="transView" destination="6jA-cO-kHv" id="N7I-PW-LrF"/>
<outlet property="toBeTransformedView" destination="6jA-cO-kHv" id="N7I-PW-LrF"/>
<outletCollection property="cornerViews" destination="kYW-iW-GWA" collectionClass="NSMutableArray" id="y8h-KH-akU"/>
<outletCollection property="cornerViews" destination="GXd-f4-Tva" collectionClass="NSMutableArray" id="XfE-oG-prx"/>
<outletCollection property="cornerViews" destination="qnW-dm-dKZ" collectionClass="NSMutableArray" id="2fG-8H-NqX"/>
@@ -109,7 +101,7 @@
</connections>
</panGestureRecognizer>
</objects>
<point key="canvasLocation" x="-570" y="887"/>
<point key="canvasLocation" x="-570.39999999999998" y="886.50674662668678"/>
</scene>
<!--Photo View Controller-->
<scene sceneID="hHO-To-AcP">