Skip to content

Commit a99d4d7

Browse files
author
Mike Richards
committed
Added all necessary files
1 parent 8a3c89c commit a99d4d7

File tree

5 files changed

+208
-24
lines changed

5 files changed

+208
-24
lines changed

faceit-swift.xcodeproj/project.pbxproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
317BB23C1FCDF1F400DC8D5B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 317BB23A1FCDF1F400DC8D5B /* Main.storyboard */; };
1313
317BB23E1FCDF1F400DC8D5B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 317BB23D1FCDF1F400DC8D5B /* Assets.xcassets */; };
1414
317BB2411FCDF1F400DC8D5B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 317BB23F1FCDF1F400DC8D5B /* LaunchScreen.storyboard */; };
15+
317BB24A1FCDF26700DC8D5B /* FaceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 317BB2491FCDF26700DC8D5B /* FaceView.swift */; };
1516
/* End PBXBuildFile section */
1617

1718
/* Begin PBXFileReference section */
@@ -22,6 +23,7 @@
2223
317BB23D1FCDF1F400DC8D5B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2324
317BB2401FCDF1F400DC8D5B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2425
317BB2421FCDF1F400DC8D5B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
26+
317BB2491FCDF26700DC8D5B /* FaceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FaceView.swift; sourceTree = "<group>"; };
2527
/* End PBXFileReference section */
2628

2729
/* Begin PBXFrameworksBuildPhase section */
@@ -54,14 +56,23 @@
5456
317BB2351FCDF1F400DC8D5B /* faceit-swift */ = {
5557
isa = PBXGroup;
5658
children = (
57-
317BB2361FCDF1F400DC8D5B /* AppDelegate.swift */,
59+
317BB2481FCDF21200DC8D5B /* Supporting Files */,
5860
317BB2381FCDF1F400DC8D5B /* ViewController.swift */,
61+
317BB2491FCDF26700DC8D5B /* FaceView.swift */,
5962
317BB23A1FCDF1F400DC8D5B /* Main.storyboard */,
63+
);
64+
path = "faceit-swift";
65+
sourceTree = "<group>";
66+
};
67+
317BB2481FCDF21200DC8D5B /* Supporting Files */ = {
68+
isa = PBXGroup;
69+
children = (
70+
317BB2361FCDF1F400DC8D5B /* AppDelegate.swift */,
6071
317BB23D1FCDF1F400DC8D5B /* Assets.xcassets */,
6172
317BB23F1FCDF1F400DC8D5B /* LaunchScreen.storyboard */,
6273
317BB2421FCDF1F400DC8D5B /* Info.plist */,
6374
);
64-
path = "faceit-swift";
75+
name = "Supporting Files";
6576
sourceTree = "<group>";
6677
};
6778
/* End PBXGroup section */
@@ -138,6 +149,7 @@
138149
files = (
139150
317BB2391FCDF1F400DC8D5B /* ViewController.swift in Sources */,
140151
317BB2371FCDF1F400DC8D5B /* AppDelegate.swift in Sources */,
152+
317BB24A1FCDF26700DC8D5B /* FaceView.swift in Sources */,
141153
);
142154
runOnlyForDeploymentPostprocessing = 0;
143155
};

faceit-swift.xcodeproj/xcuserdata/mrichards.xcuserdatad/xcschemes/faceit-swift.xcscheme

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "317BB2321FCDF1F400DC8D5B"
18+
BuildableName = "faceit-swift.app"
19+
BlueprintName = "faceit-swift"
20+
ReferencedContainer = "container:faceit-swift.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
824
</BuildAction>
925
<TestAction
1026
buildConfiguration = "Debug"
@@ -13,6 +29,15 @@
1329
shouldUseLaunchSchemeArgsEnv = "YES">
1430
<Testables>
1531
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "317BB2321FCDF1F400DC8D5B"
36+
BuildableName = "faceit-swift.app"
37+
BlueprintName = "faceit-swift"
38+
ReferencedContainer = "container:faceit-swift.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
1641
<AdditionalOptions>
1742
</AdditionalOptions>
1843
</TestAction>
@@ -26,6 +51,16 @@
2651
debugDocumentVersioning = "YES"
2752
debugServiceExtension = "internal"
2853
allowLocationSimulation = "YES">
54+
<BuildableProductRunnable
55+
runnableDebuggingMode = "0">
56+
<BuildableReference
57+
BuildableIdentifier = "primary"
58+
BlueprintIdentifier = "317BB2321FCDF1F400DC8D5B"
59+
BuildableName = "faceit-swift.app"
60+
BlueprintName = "faceit-swift"
61+
ReferencedContainer = "container:faceit-swift.xcodeproj">
62+
</BuildableReference>
63+
</BuildableProductRunnable>
2964
<AdditionalOptions>
3065
</AdditionalOptions>
3166
</LaunchAction>
@@ -35,6 +70,16 @@
3570
savedToolIdentifier = ""
3671
useCustomWorkingDirectory = "NO"
3772
debugDocumentVersioning = "YES">
73+
<BuildableProductRunnable
74+
runnableDebuggingMode = "0">
75+
<BuildableReference
76+
BuildableIdentifier = "primary"
77+
BlueprintIdentifier = "317BB2321FCDF1F400DC8D5B"
78+
BuildableName = "faceit-swift.app"
79+
BlueprintName = "faceit-swift"
80+
ReferencedContainer = "container:faceit-swift.xcodeproj">
81+
</BuildableReference>
82+
</BuildableProductRunnable>
3883
</ProfileAction>
3984
<AnalyzeAction
4085
buildConfiguration = "Debug">
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="17B48" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
59
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--View Controller-->
913
<scene sceneID="tne-QT-ifu">
1014
<objects>
11-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
15+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="faceit_swift" customModuleProvider="target" sceneMemberID="viewController">
1216
<layoutGuides>
1317
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
1418
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1519
</layoutGuides>
1620
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1721
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1822
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<subviews>
24+
<view contentMode="redraw" translatesAutoresizingMaskIntoConstraints="NO" id="IWI-4m-cAO" customClass="FaceView" customModule="faceit_swift" customModuleProvider="target">
25+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
26+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
27+
<userDefinedRuntimeAttributes>
28+
<userDefinedRuntimeAttribute type="number" keyPath="mouthCurvature">
29+
<real key="value" value="1"/>
30+
</userDefinedRuntimeAttribute>
31+
<userDefinedRuntimeAttribute type="number" keyPath="lineWidth">
32+
<real key="value" value="5"/>
33+
</userDefinedRuntimeAttribute>
34+
<userDefinedRuntimeAttribute type="boolean" keyPath="eyesOpen" value="YES"/>
35+
<userDefinedRuntimeAttribute type="number" keyPath="scale">
36+
<real key="value" value="0.90000000000000002"/>
37+
</userDefinedRuntimeAttribute>
38+
<userDefinedRuntimeAttribute type="color" keyPath="color">
39+
<color key="value" red="0.0" green="0.50196081400000003" blue="0.25098040700000002" alpha="1" colorSpace="calibratedRGB"/>
40+
</userDefinedRuntimeAttribute>
41+
</userDefinedRuntimeAttributes>
42+
</view>
43+
</subviews>
1944
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
45+
<constraints>
46+
<constraint firstAttribute="trailing" secondItem="IWI-4m-cAO" secondAttribute="trailing" id="3UG-Jw-Gao"/>
47+
<constraint firstItem="IWI-4m-cAO" firstAttribute="bottom" secondItem="wfy-db-euE" secondAttribute="top" id="Zkl-Ia-cIg"/>
48+
<constraint firstItem="IWI-4m-cAO" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="bI5-Kr-kFf"/>
49+
<constraint firstItem="IWI-4m-cAO" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="ybg-sp-Uu8"/>
50+
</constraints>
2051
</view>
2152
</viewController>
2253
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2354
</objects>
55+
<point key="canvasLocation" x="-98.400000000000006" y="122.78860569715144"/>
2456
</scene>
2557
</scenes>
2658
</document>

faceit-swift/FaceView.swift

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,121 @@
88

99
import UIKit
1010

11+
@IBDesignable
1112
class FaceView: UIView {
1213

13-
/*
14-
// Only override draw() if you perform custom drawing.
15-
// An empty implementation adversely affects performance during animation.
14+
@IBInspectable
15+
var scale: CGFloat = 0.9
16+
17+
@IBInspectable
18+
var eyesOpen: Bool = true
19+
20+
@IBInspectable
21+
var mouthCurvature: Double = -0.5 // 1.0 is full smile and -1.0 is full frown
22+
23+
@IBInspectable
24+
var lineWidth: CGFloat = 5.0
25+
26+
@IBInspectable
27+
var color: UIColor = UIColor.blue
28+
29+
private var skullRadius: CGFloat {
30+
return min(bounds.size.width, bounds.size.height) / 2 * scale
31+
}
32+
33+
private var skullCenter: CGPoint {
34+
return CGPoint(x: bounds.midX, y: bounds.midY)
35+
}
36+
37+
private enum Eye {
38+
case left
39+
case right
40+
}
41+
42+
private func pathForMouth() -> UIBezierPath {
43+
let mouthWidth = skullRadius / Ratios.skullRadiusToMouthWidth
44+
let mouthHeight = skullRadius / Ratios.skullRadiusToMouthHeight
45+
let mouthOffset = skullRadius / Ratios.skullRadiusToMouthOffset
46+
47+
let mouthRect = CGRect(x: skullCenter.x - mouthWidth / 2,
48+
y: skullCenter.y + mouthOffset,
49+
width: mouthWidth,
50+
height: mouthHeight)
51+
52+
let smileOffset = CGFloat(max(-1, min(mouthCurvature, 1))) * mouthRect.height
53+
54+
let start = CGPoint(x: mouthRect.minX, y: mouthRect.midY)
55+
let end = CGPoint(x: mouthRect.maxX, y: mouthRect.midY)
56+
57+
let cp1 = CGPoint(x: start.x + mouthRect.width / 3, y: start.y + smileOffset)
58+
let cp2 = CGPoint(x: end.x - mouthRect.width / 3, y: start.y + smileOffset)
59+
60+
let path = UIBezierPath()
61+
62+
path.move(to: start)
63+
path.addCurve(to: end, controlPoint1: cp1, controlPoint2: cp2)
64+
65+
path.lineWidth = lineWidth
66+
67+
return path
68+
}
69+
70+
private func pathForEye(_ eye: Eye) -> UIBezierPath {
71+
72+
func centerOfEye(_ eye: Eye) -> CGPoint {
73+
let eyeOffset = skullRadius / Ratios.skullRadiusToEyeOffset
74+
75+
var eyeCenter = skullCenter
76+
eyeCenter.y -= eyeOffset
77+
eyeCenter.x += ((eye == .left) ? -1 : 1) * eyeOffset
78+
79+
return eyeCenter
80+
}
81+
82+
let eyeRadius = skullRadius / Ratios.skullRadiusToEyeRadius
83+
let eyeCenter = centerOfEye(eye)
84+
85+
let path: UIBezierPath
86+
87+
if (eyesOpen) {
88+
path = UIBezierPath(arcCenter: eyeCenter, radius: eyeRadius, startAngle: 0, endAngle: 2 * CGFloat.pi, clockwise: true)
89+
} else {
90+
path = UIBezierPath()
91+
path.move(to: CGPoint(x: eyeCenter.x - eyeRadius, y: eyeCenter.y))
92+
path.addLine(to: CGPoint(x: eyeCenter.x + eyeRadius, y: eyeCenter.y))
93+
}
94+
95+
path.lineWidth = lineWidth
96+
97+
return path
98+
}
99+
100+
private func pathForSkull() -> UIBezierPath {
101+
102+
let path = UIBezierPath(arcCenter: skullCenter,
103+
radius: skullRadius,
104+
startAngle: 0,
105+
endAngle: 2 * CGFloat.pi,
106+
clockwise: false)
107+
108+
path.lineWidth = lineWidth
109+
110+
return path
111+
}
112+
16113
override func draw(_ rect: CGRect) {
17-
// Drawing code
114+
color.set()
115+
pathForSkull().stroke()
116+
pathForEye(.left).stroke()
117+
pathForEye(.right).stroke()
118+
pathForMouth().stroke()
119+
}
120+
121+
private struct Ratios {
122+
static let skullRadiusToEyeOffset: CGFloat = 3
123+
static let skullRadiusToEyeRadius: CGFloat = 10
124+
static let skullRadiusToMouthWidth: CGFloat = 1
125+
static let skullRadiusToMouthHeight: CGFloat = 3
126+
static let skullRadiusToMouthOffset: CGFloat = 3
18127
}
19-
*/
20-
21128
}

faceit-swift/ViewController.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,5 @@
99
import UIKit
1010

1111
class ViewController: UIViewController {
12-
13-
override func viewDidLoad() {
14-
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
16-
}
17-
18-
override func didReceiveMemoryWarning() {
19-
super.didReceiveMemoryWarning()
20-
// Dispose of any resources that can be recreated.
21-
}
22-
23-
2412
}
2513

0 commit comments

Comments
 (0)