Skip to content

Commit

Permalink
Merge pull request #21 from Boris-Em/sampleAppImprovements
Browse files Browse the repository at this point in the history
Various fixes for Xcode beta 4
  • Loading branch information
chrischute authored Jul 27, 2017
2 parents 9c2706c + a927fad commit f6ebf1a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
6 changes: 3 additions & 3 deletions SampleApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.19" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13168.3" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.16"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13147.4"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -162,7 +162,7 @@
<segment title="Fade"/>
</segments>
<connections>
<action selector="handleLongPressAnimationSegmentControlValueChange:" destination="gzb-DA-RSG" eventType="valueChanged" id="lbn-On-u8G"/>
<action selector="handleLongPressAnimationSegmentControlValueChange:" destination="gzb-DA-RSG" eventType="valueChanged" id="NZR-av-7dP"/>
</connections>
</segmentedControl>
</subviews>
Expand Down
35 changes: 22 additions & 13 deletions SampleApp/FocusSquare.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ class FocusSquare: SCNNode {
return 1.0
}

private func pulseAction() -> SCNAction {
private func pulseAction() -> SCNAction? {
let pulseOutAction = SCNAction.fadeOpacity(to: 0.4, duration: 0.5)
let pulseInAction = SCNAction.fadeOpacity(to: 1.0, duration: 0.5)
pulseOutAction.timingMode = .easeInEaseOut
pulseInAction.timingMode = .easeInEaseOut

return SCNAction.repeatForever(SCNAction.sequence([pulseOutAction, pulseInAction]))
if let sequence = SCNAction.sequence([pulseOutAction, pulseInAction]) {
return SCNAction.repeatForever(sequence)
}

return nil
}

private func stopPulsing(for node: SCNNode?) {
Expand Down Expand Up @@ -182,7 +186,9 @@ class FocusSquare: SCNNode {
self.segments?[5].open(direction: .down, newLength: sideLengthForOpenSquareSegments)
self.segments?[6].open(direction: .left, newLength: sideLengthForOpenSquareSegments)
self.segments?[7].open(direction: .right, newLength: sideLengthForOpenSquareSegments)
SCNTransaction.completionBlock = { self.entireSquare?.runAction(self.pulseAction(), forKey: "pulse") }
if let pulseAction = self.pulseAction() {
SCNTransaction.completionBlock = { self.entireSquare?.runAction(pulseAction, forKey: "pulse") }
}
SCNTransaction.commit()

// Scale/bounce animation
Expand Down Expand Up @@ -231,22 +237,25 @@ class FocusSquare: SCNNode {
entireSquare?.addAnimation(scaleAnimation(for: "transform.scale.y"), forKey: "transform.scale.y")
entireSquare?.addAnimation(scaleAnimation(for: "transform.scale.z"), forKey: "transform.scale.z")

// Flash
if flash {
let waitAction = SCNAction.wait(duration: animationDuration * 0.75)
let fadeInAction = SCNAction.fadeOpacity(to: 0.25, duration: animationDuration * 0.125)
let fadeAction = SCNAction.fadeOpacity(to: 0.0, duration: animationDuration * 0.125)
fillPlane?.runAction(SCNAction.sequence([waitAction, fadeInAction, fadeAction]))
if let sequence = SCNAction.sequence([waitAction, fadeInAction, fadeAction]) {
fillPlane?.runAction(sequence)
}

let flashSquareAction = flashAnimation(duration: animationDuration * 0.25)
segments?[0].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[1].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[2].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[3].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[4].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[5].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[6].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
segments?[7].runAction(SCNAction.sequence([waitAction, flashSquareAction]))
if let sequence = SCNAction.sequence([waitAction, flashSquareAction]) {
segments?[0].runAction(sequence)
segments?[1].runAction(sequence)
segments?[2].runAction(sequence)
segments?[3].runAction(sequence)
segments?[4].runAction(sequence)
segments?[5].runAction(sequence)
segments?[6].runAction(sequence)
segments?[7].runAction(sequence)
}

}

Expand Down
12 changes: 10 additions & 2 deletions SampleApp/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,19 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate {
// MARK: Actions

@IBAction func handleEntranceAnimationSegmentControlValueChange(_ sender: UISegmentedControl) {
settings?.animationType = settings?.entranceAnimationType(forIndex: sender.selectedSegmentIndex) ?? .fade
if let entranceAnimationType = settings?.entranceAnimationType(forIndex: sender.selectedSegmentIndex) {
settings?.animationType = entranceAnimationType
} else {
settings?.animationType = .fade
}
}

@IBAction func handleLongPressAnimationSegmentControlValueChange(_ sender: UISegmentedControl) {
settings?.longPressAnimationType = settings?.longPressAnimationType(forIndex: sender.selectedSegmentIndex) ?? .shrink
if let longPressAnimationType = settings?.longPressAnimationType(forIndex: sender.selectedSegmentIndex){
settings?.longPressAnimationType = longPressAnimationType
} else {
settings?.longPressAnimationType = .shrink
}
}

@IBAction func handleOpacitySliderValueChange(_ sender: UISlider) {
Expand Down
2 changes: 1 addition & 1 deletion SampleApp/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension UIImage {
guard let ciImage = CIImage(image: self) else {
return nil
}
return UIImage(ciImage: ciImage.applyingFilter("CIColorInvert", withInputParameters: nil))
return UIImage(ciImage: ciImage.applyingFilter("CIColorInvert", parameters: [String: Any]()))
}

static func composeButtonImage(from thumbImage: UIImage, alpha: CGFloat = 1.0) -> UIImage {
Expand Down
16 changes: 8 additions & 8 deletions SampleApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class ViewController: UIViewController, ARSCNViewDelegate, SettingsDelegate, UIP

var barChart: ARBarChart?
private let arKitColors = [
UIColor(colorLiteralRed: 238.0 / 255.0, green: 109.0 / 255.0, blue: 150.0 / 255.0, alpha: 1.0),
UIColor(colorLiteralRed: 70.0 / 255.0, green: 150.0 / 255.0, blue: 150.0 / 255.0, alpha: 1.0),
UIColor(colorLiteralRed: 134.0 / 255.0, green: 218.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0),
UIColor(colorLiteralRed: 237.0 / 255.0, green: 231.0 / 255.0, blue: 254.0 / 255.0, alpha: 1.0),
UIColor(colorLiteralRed: 0.0 / 255.0, green: 110.0 / 255.0, blue: 235.0 / 255.0, alpha: 1.0),
UIColor(colorLiteralRed: 193.0 / 255.0, green: 193.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0),
UIColor(colorLiteralRed: 84.0 / 255.0, green: 204.0 / 255.0, blue: 254.0 / 255.0, alpha: 1.0)
UIColor(red: 238.0 / 255.0, green: 109.0 / 255.0, blue: 150.0 / 255.0, alpha: 1.0),
UIColor(red: 70.0 / 255.0, green: 150.0 / 255.0, blue: 150.0 / 255.0, alpha: 1.0),
UIColor(red: 134.0 / 255.0, green: 218.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0),
UIColor(red: 237.0 / 255.0, green: 231.0 / 255.0, blue: 254.0 / 255.0, alpha: 1.0),
UIColor(red: 0.0 / 255.0, green: 110.0 / 255.0, blue: 235.0 / 255.0, alpha: 1.0),
UIColor(red: 193.0 / 255.0, green: 193.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0),
UIColor(red: 84.0 / 255.0, green: 204.0 / 255.0, blue: 254.0 / 255.0, alpha: 1.0)
]

var session: ARSession {
Expand Down Expand Up @@ -234,7 +234,7 @@ class ViewController: UIViewController, ARSCNViewDelegate, SettingsDelegate, UIP
guard gestureRecognizer.state == .began else { return }
var labelToHighlight: ARChartLabel?

let animationStyle = ARChartHighlighter.AnimationStyle.shrink
let animationStyle = settings.longPressAnimationType
let animationDuration = 0.3
let longPressLocation = gestureRecognizer.location(in: self.view)
let selectedNode = self.sceneView.hitTest(longPressLocation, options: nil).first?.node
Expand Down

0 comments on commit f6ebf1a

Please sign in to comment.