Skip to content

Commit de1a1eb

Browse files
Peter VanhoefPeter Vanhoef
Peter Vanhoef
authored and
Peter Vanhoef
committed
Implemented part c of task 11 (closes #11)
1 parent 8c4340e commit de1a1eb

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

Calculator/Calculator/Base.lproj/Main.storyboard

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="fcY-c8-IEH">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="fcY-c8-IEH">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -77,7 +77,7 @@
7777
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FnA-Yx-lDt">
7878
<rect key="frame" x="0.0" y="0.0" width="53" height="96"/>
7979
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
80-
<fontDescription key="fontDescription" type="system" pointSize="25"/>
80+
<fontDescription key="fontDescription" type="system" pointSize="23"/>
8181
<state key="normal" title="→M">
8282
<color key="titleColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
8383
</state>
@@ -132,7 +132,7 @@
132132
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dtK-K0-MGK">
133133
<rect key="frame" x="290" y="0.0" width="53" height="96"/>
134134
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
135-
<fontDescription key="fontDescription" type="system" pointSize="15"/>
135+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
136136
<state key="normal" title="Graph">
137137
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
138138
</state>
@@ -148,7 +148,7 @@
148148
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tLe-zK-OUJ">
149149
<rect key="frame" x="0.0" y="0.0" width="53" height="95.5"/>
150150
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
151-
<fontDescription key="fontDescription" type="system" pointSize="25"/>
151+
<fontDescription key="fontDescription" type="system" pointSize="24"/>
152152
<state key="normal" title="cos">
153153
<color key="titleColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
154154
</state>
@@ -528,6 +528,6 @@
528528
</scene>
529529
</scenes>
530530
<inferredMetricsTieBreakers>
531-
<segue reference="jyr-Pc-8eS"/>
531+
<segue reference="Zbq-q6-BA9"/>
532532
</inferredMetricsTieBreakers>
533533
</document>

Calculator/Calculator/GraphingView.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ class GraphingView: UIView {
4444
}
4545
}
4646

47+
func setOrigin(byReactingTo tapRecognizer: UITapGestureRecognizer) {
48+
switch tapRecognizer.state {
49+
case .changed, .ended:
50+
origin = tapRecognizer.location(in: self)
51+
default:
52+
break
53+
}
54+
}
55+
4756
private var axesDrawer = AxesDrawer(color: UIColor.black, contentScaleFactor: 1.0)
4857

4958
private func pathForUnaryFunction() -> UIBezierPath {
5059
let path = UIBezierPath()
5160

52-
if dataSource != nil {
61+
if dataSource != nil && origin != nil {
5362
// iterate over every pixel of the width of the view
5463
let numberOfPixelsHorizontally = Int(bounds.size.width * contentScaleFactor)
5564
var firstPixel = true

Calculator/Calculator/GraphingViewController.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ class GraphingViewController: UIViewController, GraphingViewDataSource {
2121
// Dispose of any resources that can be recreated.
2222
}
2323

24-
25-
/*
26-
// MARK: - Navigation
27-
28-
// In a storyboard-based application, you will often want to do a little preparation before navigation
29-
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
30-
// Get the new view controller using segue.destinationViewController.
31-
// Pass the selected object to the new view controller.
32-
}
33-
*/
34-
3524
@IBOutlet weak var graphingView: GraphingView! {
3625
didSet {
3726
graphingView.dataSource = self
@@ -41,6 +30,10 @@ class GraphingViewController: UIViewController, GraphingViewDataSource {
4130

4231
let panRecognizer = UIPanGestureRecognizer(target: graphingView, action: #selector(graphingView.moveOrigin(byReactingTo:)))
4332
graphingView.addGestureRecognizer(panRecognizer)
33+
34+
let tapRecognizer = UITapGestureRecognizer(target: graphingView, action: #selector(graphingView.setOrigin(byReactingTo:)))
35+
tapRecognizer.numberOfTapsRequired = 2
36+
graphingView.addGestureRecognizer(tapRecognizer)
4437
}
4538
}
4639

0 commit comments

Comments
 (0)