add resetAnchorPoint from tests to example

This commit is contained in:
Paul Zabelin
2018-01-05 17:25:05 -08:00
parent aba5e189f6
commit 5e088c2fa3
5 changed files with 56 additions and 24 deletions

View File

@@ -22,6 +22,8 @@
4BA7B1531C816DCE00933779 /* sky.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4B2D2E8C1C7C323D0045FD11 /* sky.jpg */; };
4BDEE37320004185007214F1 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDEE37220004185007214F1 /* PhotoViewController.swift */; };
4BDEE374200049CD007214F1 /* with-overlay.svg in Resources */ = {isa = PBXBuildFile; fileRef = 4B2D2E891C7C2E620045FD11 /* with-overlay.svg */; };
4BDEE37620005B6D007214F1 /* resetAnchorPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDEE37520005B6D007214F1 /* resetAnchorPoint.swift */; };
4BDEE37720005B6D007214F1 /* resetAnchorPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDEE37520005B6D007214F1 /* resetAnchorPoint.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* PanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* PanViewController.swift */; };
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
@@ -62,6 +64,7 @@
4BA7B1481C7C7A0600933779 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; name = .travis.yml; path = ../.travis.yml; sourceTree = "<group>"; };
4BA7B14D1C7D710D00933779 /* ReferenceImages */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ReferenceImages; sourceTree = "<group>"; };
4BDEE37220004185007214F1 /* PhotoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; };
4BDEE37520005B6D007214F1 /* resetAnchorPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = resetAnchorPoint.swift; sourceTree = "<group>"; };
4EA2244D76A3BF4D89D92FD5 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -138,6 +141,7 @@
isa = PBXGroup;
children = (
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
4BDEE37520005B6D007214F1 /* resetAnchorPoint.swift */,
4BDEE37220004185007214F1 /* PhotoViewController.swift */,
607FACD71AFB9204008FA782 /* PanViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
@@ -420,6 +424,7 @@
buildActionMask = 2147483647;
files = (
607FACD81AFB9204008FA782 /* PanViewController.swift in Sources */,
4BDEE37620005B6D007214F1 /* resetAnchorPoint.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
4BDEE37320004185007214F1 /* PhotoViewController.swift in Sources */,
);
@@ -438,6 +443,7 @@
4B1B1C091C7A64F7003F8165 /* CATransform3Dfrom2DSpec.swift in Sources */,
4B1B1C0B1C7A687E003F8165 /* HomogeneousInverseSpec.swift in Sources */,
4B1B1C081C7A64BF003F8165 /* ProjectionSpec.swift in Sources */,
4BDEE37720005B6D007214F1 /* resetAnchorPoint.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -6,6 +6,8 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -119,17 +121,38 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" fixedFrame="YES" image="container.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="Sat-yN-TXs">
<rect key="frame" x="23" y="82" width="555" height="435"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" fixedFrame="YES" image="sky.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="ESD-2C-OL5">
<rect key="frame" x="140" y="180" width="320" height="240"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="OtV-dV-2YR">
<rect key="frame" x="3" y="62" width="555" height="475"/>
<subviews>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" image="container.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="Sat-yN-TXs">
<rect key="frame" x="0.0" y="0.0" width="555" height="475"/>
</imageView>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" image="sky.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="ESD-2C-OL5">
<rect key="frame" x="117" y="118" width="320" height="240"/>
<constraints>
<constraint firstAttribute="width" constant="320" id="0EV-Mr-hdE"/>
<constraint firstAttribute="width" secondItem="ESD-2C-OL5" secondAttribute="height" multiplier="4:3" id="j2Z-Tv-m3a"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="ESD-2C-OL5" firstAttribute="centerY" secondItem="OtV-dV-2YR" secondAttribute="centerY" id="IkS-PJ-yYe"/>
<constraint firstAttribute="trailing" secondItem="Sat-yN-TXs" secondAttribute="trailing" id="Jvf-6f-Rks"/>
<constraint firstItem="ESD-2C-OL5" firstAttribute="centerX" secondItem="OtV-dV-2YR" secondAttribute="centerX" id="djC-ah-Y45"/>
<constraint firstAttribute="bottom" secondItem="Sat-yN-TXs" secondAttribute="bottom" id="eXt-2Z-BPW"/>
<constraint firstItem="Sat-yN-TXs" firstAttribute="top" secondItem="OtV-dV-2YR" secondAttribute="top" id="k2f-nw-pDt"/>
<constraint firstItem="Sat-yN-TXs" firstAttribute="leading" secondItem="OtV-dV-2YR" secondAttribute="leading" id="muK-uI-ikl"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="OtV-dV-2YR" firstAttribute="leading" secondItem="OAe-Sl-oWH" secondAttribute="leadingMargin" constant="-13" id="04D-lL-4Bd"/>
<constraint firstItem="OtV-dV-2YR" firstAttribute="top" secondItem="3Q0-A6-ux3" secondAttribute="bottom" constant="42" id="Twg-Zm-U00"/>
<constraint firstItem="KJh-jd-AO7" firstAttribute="top" secondItem="OtV-dV-2YR" secondAttribute="bottom" constant="81" id="Xmh-R3-m3Z"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="h5q-E4-AbS" appends="YES" id="bob-eg-BCl"/>
</connections>
@@ -156,6 +179,7 @@
<tabBarController automaticallyAdjustsScrollViewInsets="NO" id="GDb-qn-IKv" sceneMemberID="viewController">
<toolbarItems/>
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="PIL-7H-als">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>

View File

@@ -26,6 +26,7 @@ class FittingPolygon {
}
assert(points.count == 4, "should have 4 point")
points = [points[3], points[0], points[2], points[1]]
print("points:", points)
}
class func loadFromSvgFile() -> FittingPolygon {
@@ -44,9 +45,6 @@ class PolygonLoader: NSObject {
let fileName: String = String(name.first!)
let fileExtension: String = String(name.last!)
svgFileUrl = bundle.url(forResource: fileName, withExtension: fileExtension)!
let contents = try! String(contentsOf: svgFileUrl)
print(contents)
assert(contents.count > 10, "too short content")
}
func load() -> FittingPolygon {
@@ -81,8 +79,12 @@ class PhotoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
overlayImageView.center = containerImageView.center
applyTranformation()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
overlayImageView.resetAnchorPoint()
toggleTransform()
}
@IBAction func didTap(_ sender: UITapGestureRecognizer) {
@@ -103,9 +105,7 @@ class PhotoViewController: UIViewController {
func tranformation() -> CATransform3D {
let start = Perspective(overlayImageView.frame)
let transform = FittingPolygon.loadFromSvgFile()
var destination = Perspective(overlayImageView.frame)
print("transform.points:", transform.points)
destination = Perspective(transform.points)
let destination = Perspective(transform.points)
return start.projectiveTransform(destination: destination)
}

View File

@@ -0,0 +1,10 @@
import UIKit
import QuartzCore
public extension UIView {
public func resetAnchorPoint() {
let rect = frame
layer.anchorPoint = CGPoint.zero
frame = rect
}
}

View File

@@ -4,14 +4,6 @@ import Nimble_Snapshots
import PerspectiveTransform
import Foundation
public extension UIView {
public func resetAnchorPoint() {
let rect = frame
layer.anchorPoint = CGPoint.zero
frame = rect
}
}
class SnapshotSpec: QuickSpec {
override func spec() {
describe("overlay placement") {