Skip to content

Commit

Permalink
Add debug button
Browse files Browse the repository at this point in the history
  • Loading branch information
mludowise committed Aug 7, 2017
1 parent baf9a18 commit b87ad34
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 16 deletions.
49 changes: 36 additions & 13 deletions ARKitRectangleDetection/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,65 @@
<constraint firstItem="ZBl-Tv-UYE" firstAttribute="leading" secondItem="Wcr-4o-ghG" secondAttribute="leading" constant="16" id="sXx-WH-OCR"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6YM-9t-ZZe">
<rect key="frame" x="307" y="20" width="52" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6OC-Jo-UXh">
<rect key="frame" x="293" y="36" width="66" height="34"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.5" colorSpace="calibratedRGB"/>
<inset key="contentEdgeInsets" minX="8" minY="8" maxX="8" maxY="8"/>
<state key="normal" title="Clear">
<color key="titleColor" red="1" green="1" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<state key="normal" title="Restart">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onClearButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="rVi-Uz-33i"/>
<action selector="onClearButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="Ldc-g7-2Lf"/>
<action selector="onRestartButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="fWz-OW-emi"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6OC-Jo-UXh">
<rect key="frame" x="16" y="19" width="66" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cXR-Dy-jPE">
<rect key="frame" x="16" y="36" width="62" height="34"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.5" colorSpace="calibratedRGB"/>
<color key="tintColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<inset key="contentEdgeInsets" minX="8" minY="8" maxX="8" maxY="8"/>
<state key="normal" title="Restart">
<color key="titleColor" red="1" green="1" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<state key="normal" title="Debug">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</state>
<state key="selected">
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
<connections>
<action selector="onClearButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="Ldc-g7-2Lf"/>
<action selector="onRestartButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="fWz-OW-emi"/>
<action selector="onClearButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="mzD-Mn-RqD"/>
<action selector="onDebugButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="6sY-1r-WOn"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6YM-9t-ZZe">
<rect key="frame" x="190" y="36" width="95" height="34"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.5" colorSpace="calibratedRGB"/>
<inset key="contentEdgeInsets" minX="8" minY="8" maxX="8" maxY="8"/>
<state key="normal" title="Clear Rects">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onClearButton:" destination="MOP-cd-TFu" eventType="touchUpInside" id="rVi-Uz-33i"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Wcr-4o-ghG" firstAttribute="bottom" secondItem="zmo-nJ-q2Z" secondAttribute="bottom" id="8dc-QZ-K3W"/>
<constraint firstItem="6YM-9t-ZZe" firstAttribute="centerY" secondItem="cXR-Dy-jPE" secondAttribute="centerY" id="FnO-sp-bnn"/>
<constraint firstItem="zmo-nJ-q2Z" firstAttribute="trailing" secondItem="6OC-Jo-UXh" secondAttribute="trailing" constant="16" id="OCU-dE-gtN"/>
<constraint firstItem="cXR-Dy-jPE" firstAttribute="leading" secondItem="zmo-nJ-q2Z" secondAttribute="leading" constant="16" id="PiD-YB-CeS"/>
<constraint firstItem="Wcr-4o-ghG" firstAttribute="trailing" secondItem="zmo-nJ-q2Z" secondAttribute="trailing" id="TIK-VO-ejK"/>
<constraint firstItem="6OC-Jo-UXh" firstAttribute="leading" secondItem="6YM-9t-ZZe" secondAttribute="trailing" constant="8" id="i6l-Y3-XiG"/>
<constraint firstItem="Wcr-4o-ghG" firstAttribute="leading" secondItem="zmo-nJ-q2Z" secondAttribute="leading" id="le0-HY-pWl"/>
<constraint firstItem="cXR-Dy-jPE" firstAttribute="top" secondItem="zmo-nJ-q2Z" secondAttribute="top" constant="16" id="plF-RX-eoW"/>
<constraint firstItem="6YM-9t-ZZe" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="cXR-Dy-jPE" secondAttribute="trailing" constant="16" id="qyk-86-L3s"/>
<constraint firstItem="6OC-Jo-UXh" firstAttribute="centerY" secondItem="cXR-Dy-jPE" secondAttribute="centerY" id="uD8-tK-Gbp"/>
</constraints>
<viewLayoutGuide key="safeArea" id="zmo-nJ-q2Z"/>
</view>
<nil key="simulatedStatusBarMetrics"/>
<connections>
<outlet property="clearButton" destination="6YM-9t-ZZe" id="aKc-OP-hCE"/>
<outlet property="debugButton" destination="cXR-Dy-jPE" id="mUo-Tn-xm0"/>
<outlet property="messageLabel" destination="ZBl-Tv-UYE" id="vD6-Ss-dis"/>
<outlet property="messageView" destination="Wcr-4o-ghG" id="SXn-dX-OUd"/>
<outlet property="restartButton" destination="6OC-Jo-UXh" id="i4T-mH-NRY"/>
Expand Down
36 changes: 33 additions & 3 deletions ARKitRectangleDetection/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
@IBOutlet weak var messageView: UIView!
@IBOutlet weak var clearButton: UIButton!
@IBOutlet weak var restartButton: UIButton!
@IBOutlet weak var debugButton: UIButton!


// MARK: - Internal properties used to identify the rectangle the user is selecting
Expand Down Expand Up @@ -50,7 +51,15 @@ class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {

// MARK: - Debug properties

var showDebugOptions = true
var showDebugOptions = false {
didSet {
if showDebugOptions {
sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
} else {
sceneView.debugOptions = []
}
}
}


// MARK: - Message displayed to the user
Expand All @@ -73,6 +82,12 @@ class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {

// MARK: - UIViewController

override var prefersStatusBarHidden: Bool {
get {
return true
}
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -98,8 +113,10 @@ class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
message = nil

// Style clear button
styleButton(clearButton, localizedTitle: NSLocalizedString("Clear", comment: ""))
styleButton(clearButton, localizedTitle: NSLocalizedString("Clear Rects", comment: ""))
styleButton(restartButton, localizedTitle: NSLocalizedString("Restart", comment: ""))
styleButton(debugButton, localizedTitle: NSLocalizedString("Debug", comment: ""))
debugButton.isSelected = showDebugOptions
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -186,6 +203,19 @@ class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
message = .helpFindSurface
}

@IBAction func onDebugButton(_ sender: Any) {
showDebugOptions = !showDebugOptions
debugButton.isSelected = showDebugOptions

if showDebugOptions {
debugButton.layer.backgroundColor = UIColor.yellow.cgColor
debugButton.layer.borderColor = UIColor.yellow.cgColor
} else {
debugButton.layer.backgroundColor = UIColor.black.withAlphaComponent(0.5).cgColor
debugButton.layer.borderColor = UIColor.white.cgColor
}
}

// MARK: - ARSessionDelegate

// Update selected rectangle if it's been more than 1 second and the screen is still being touched
Expand Down Expand Up @@ -349,7 +379,7 @@ class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
}

private func styleButton(_ button: UIButton, localizedTitle: String?) {
button.layer.borderColor = UIColor.yellow.cgColor
button.layer.borderColor = UIColor.white.cgColor
button.layer.borderWidth = 1
button.layer.cornerRadius = 4
button.setTitle(localizedTitle, for: .normal)
Expand Down

0 comments on commit b87ad34

Please sign in to comment.