Skip to content

Commit 01cb8c8

Browse files
author
Cesar Vargas Casaseca
committed
Handle images layout, refactor view model to make it less complex.
1 parent 11bbd9c commit 01cb8c8

File tree

21 files changed

+283
-65
lines changed

21 files changed

+283
-65
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "Untitled.png",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
275 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "pngwave (3).png",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
30.8 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "rightEye.png",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
277 KB
Loading

Warhol/SampleApp/Main.storyboard

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
77
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
88
</dependencies>
@@ -17,25 +17,36 @@
1717
<subviews>
1818
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="uDo-iR-BPQ">
1919
<rect key="frame" x="16" y="60" width="343" height="30"/>
20-
<state key="normal" title="Open Camera"/>
20+
<state key="normal" title="Open Camera With Client Drawing"/>
2121
<connections>
22-
<action selector="openCameraButtonWasPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="d01-2r-kda"/>
22+
<action selector="openCameraWithClientDrawingButtonWasPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="d01-2r-kda"/>
2323
</connections>
2424
</button>
2525
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LVo-vQ-Ima">
2626
<rect key="frame" x="16" y="104" width="343" height="30"/>
27+
<state key="normal" title="Open Camera With Images on Features"/>
28+
<connections>
29+
<action selector="openCameraWithImageFeatures:" destination="BYZ-38-t0r" eventType="touchUpInside" id="vlp-Ta-9Ja"/>
30+
</connections>
31+
</button>
32+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Lif-Qj-t4h">
33+
<rect key="frame" x="16" y="148" width="343" height="30"/>
2734
<state key="normal" title="Open Image"/>
2835
<connections>
29-
<action selector="openImageButtonWasPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="LMk-oy-MoV"/>
36+
<action selector="openImageButtonWasPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="nOM-6a-Hys"/>
3037
</connections>
3138
</button>
3239
</subviews>
3340
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3441
<constraints>
3542
<constraint firstItem="LVo-vQ-Ima" firstAttribute="width" secondItem="uDo-iR-BPQ" secondAttribute="width" id="5VQ-kT-uDa"/>
43+
<constraint firstItem="Lif-Qj-t4h" firstAttribute="trailing" secondItem="LVo-vQ-Ima" secondAttribute="trailing" id="AAt-Le-BXB"/>
44+
<constraint firstItem="Lif-Qj-t4h" firstAttribute="top" secondItem="LVo-vQ-Ima" secondAttribute="bottom" constant="14" id="N9F-FT-O76"/>
45+
<constraint firstItem="Lif-Qj-t4h" firstAttribute="leading" secondItem="LVo-vQ-Ima" secondAttribute="leading" id="Qpm-ms-l9g"/>
3646
<constraint firstItem="LVo-vQ-Ima" firstAttribute="trailing" secondItem="uDo-iR-BPQ" secondAttribute="trailing" id="c1L-K9-dti"/>
3747
<constraint firstItem="uDo-iR-BPQ" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="d7p-9t-Nq5"/>
3848
<constraint firstItem="LVo-vQ-Ima" firstAttribute="leading" secondItem="uDo-iR-BPQ" secondAttribute="leading" id="gZK-Vx-gKp"/>
49+
<constraint firstItem="Lif-Qj-t4h" firstAttribute="height" secondItem="LVo-vQ-Ima" secondAttribute="height" id="kt5-uA-jxc"/>
3950
<constraint firstItem="LVo-vQ-Ima" firstAttribute="height" secondItem="uDo-iR-BPQ" secondAttribute="height" id="mZI-LG-rSx"/>
4051
<constraint firstItem="LVo-vQ-Ima" firstAttribute="top" secondItem="uDo-iR-BPQ" secondAttribute="bottom" constant="14" id="myE-ab-Hf9"/>
4152
<constraint firstItem="uDo-iR-BPQ" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="60" id="paf-yI-Iyn"/>

Warhol/SampleApp/View/CameraFrontView.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,10 @@ final class FaceView: UIView, CameraFrontView {
3131
context.strokePath()
3232
UIColor.white.setStroke()
3333

34-
draw(landmark: viewModel.leftEye, closePath: true, in: context)
35-
draw(landmark: viewModel.rightEye, closePath: true, in: context)
36-
37-
draw(landmark: viewModel.leftEyebrow, closePath: false, in: context)
38-
draw(landmark: viewModel.rightEyebrow, closePath: false, in: context)
39-
40-
draw(landmark: viewModel.nose, closePath: false, in: context)
41-
42-
draw(landmark: viewModel.outerLips, closePath: true, in: context)
43-
draw(landmark: viewModel.innerLips, closePath: true, in: context)
44-
45-
draw(landmark: viewModel.faceContour, closePath: false, in: context)
34+
Array(viewModel.landmarks.values).forEach {self.draw(landmark: $0, closePath: true, in: context) }
4635
}
4736

48-
private func draw(landmark: FaceLandmark, closePath: Bool, in context: CGContext) {
37+
private func draw(landmark: FaceLandmarkPerimeter, closePath: Bool, in context: CGContext) {
4938
guard !landmark.isEmpty else {
5039
return
5140
}

Warhol/SampleApp/ViewController/ImageViewController.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,10 @@ final class ImageViewController: UIViewController {
4141
context.strokePath()
4242
UIColor.blue.setStroke()
4343

44-
self.draw(landmark: viewModel.leftEye, closePath: true, in: context)
45-
self.draw(landmark: viewModel.rightEye, closePath: true, in: context)
46-
47-
self.draw(landmark: viewModel.leftEyebrow, closePath: false, in: context)
48-
self.draw(landmark: viewModel.rightEyebrow, closePath: false, in: context)
49-
50-
self.draw(landmark: viewModel.nose, closePath: false, in: context)
51-
52-
self.draw(landmark: viewModel.outerLips, closePath: true, in: context)
53-
self.draw(landmark: viewModel.innerLips, closePath: true, in: context)
54-
self.draw(landmark: viewModel.faceContour, closePath: false, in: context)
44+
Array(viewModel.landmarks.values).forEach { self.draw(landmark: $0, closePath: true, in: context) }
5545
}
5646

57-
private func draw(landmark: FaceLandmark, closePath: Bool, in context: CGContext) {
47+
private func draw(landmark: FaceLandmarkPerimeter, closePath: Bool, in context: CGContext) {
5848
guard !landmark.isEmpty else {
5949
return
6050
}

Warhol/SampleApp/ViewController/ViewController.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@ import UIKit
1010
import Warhol
1111

1212
class ViewController: UIViewController {
13-
@IBAction func openCameraButtonWasPressed(_ sender: Any) {
13+
@IBAction func openCameraWithClientDrawingButtonWasPressed(_ sender: Any) {
1414
let cameraViewController = CameraFaceDetectionViewController()
15+
1516
let faceView = FaceView()
1617
faceView.backgroundColor = .clear
1718
cameraViewController.cameraFrontView = faceView
19+
20+
present(cameraViewController, animated: true, completion: nil)
21+
}
22+
23+
@IBAction func openCameraWithImageFeatures(_ sender: Any) {
24+
let cameraViewController = CameraFaceDetectionViewController()
25+
26+
let leftEye = ImageLayout(image: UIImage(named: "leftEye")!, sizeRatio: SizeRatio(width: 1, height: 4))
27+
let rightEye = ImageLayout(image: UIImage(named: "rightEye")!, sizeRatio: SizeRatio(width: 1, height: 4))
28+
let nose = ImageLayout(image: UIImage(named: "nose")!)
29+
30+
let faceLayout = FaceLayout(landmarkLayouts: [.leftEye: leftEye,
31+
.rightEye: rightEye,
32+
.nose: nose])
33+
cameraViewController.faceLayout = faceLayout
34+
1835
present(cameraViewController, animated: true, completion: nil)
36+
1937
}
2038

2139
@IBAction func openImageButtonWasPressed(_ sender: Any) {

0 commit comments

Comments
 (0)