Beginning work on header view
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// ArcadeMachinesViewController.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/30/15.
|
||||
// Copyright © 2015 XION. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class ArcadeMachinesViewController: UIViewController {
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,9 @@
|
||||
import UIKit
|
||||
|
||||
class MainViewController: UIViewController {
|
||||
private var _backgroundController: BackgroundViewController = BackgroundViewController()
|
||||
private var _visualizationController: VisualizationViewController = VisualizationViewController()
|
||||
private var _machinesController: ArcadeMachinesViewController = ArcadeMachinesViewController()
|
||||
private var _headerView: HeaderView = HeaderView()
|
||||
|
||||
// MARK: Overrides
|
||||
|
||||
@@ -19,22 +21,13 @@ class MainViewController: UIViewController {
|
||||
|
||||
self.view.backgroundColor = UIColor.blackColor()
|
||||
|
||||
self.addChildViewController(_backgroundController)
|
||||
self.view.addSubview(_backgroundController.view)
|
||||
self.addChildViewController(_visualizationController)
|
||||
self.view.addSubview(_visualizationController.view)
|
||||
|
||||
let doubleTapGR = UITapGestureRecognizer(target: self, action: Selector("_handleDoubleFingerTap:"))
|
||||
doubleTapGR.numberOfTouchesRequired = 2
|
||||
self.view.addGestureRecognizer(doubleTapGR)
|
||||
self.addChildViewController(_machinesController)
|
||||
self.view.addSubview(_machinesController.view)
|
||||
|
||||
let singleTapGR = UITapGestureRecognizer(target: self, action: Selector("_handleSingleFingerTap:"))
|
||||
singleTapGR.numberOfTouchesRequired = 1
|
||||
singleTapGR.requireGestureRecognizerToFail(doubleTapGR)
|
||||
self.view.addGestureRecognizer(singleTapGR)
|
||||
}
|
||||
|
||||
override func prefersStatusBarHidden() -> Bool
|
||||
{
|
||||
return true
|
||||
self.view.addSubview(_headerView)
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews()
|
||||
@@ -42,19 +35,50 @@ class MainViewController: UIViewController {
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
let bounds = self.view.bounds
|
||||
_backgroundController.view.frame = bounds
|
||||
let headerBounds = CGRect(
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
width: bounds.size.width,
|
||||
height: rint(bounds.size.height / 10.0)
|
||||
)
|
||||
let bodyBounds = CGRect(
|
||||
x: 0.0,
|
||||
y: CGRectGetMaxY(headerBounds),
|
||||
width: bounds.size.width,
|
||||
height: bounds.size.height - headerBounds.size.height
|
||||
)
|
||||
|
||||
_headerView.frame = headerBounds
|
||||
|
||||
let visualizationFrame = CGRect(
|
||||
x: bodyBounds.origin.x,
|
||||
y: bodyBounds.origin.y,
|
||||
width: rint((5.0 / 8.0) * bodyBounds.size.width),
|
||||
height: bodyBounds.size.height
|
||||
)
|
||||
_visualizationController.view.frame = visualizationFrame
|
||||
|
||||
let machinesControllerFrame = CGRect(
|
||||
x: CGRectGetMaxX(visualizationFrame),
|
||||
y: bodyBounds.origin.y,
|
||||
width: bodyBounds.size.width - visualizationFrame.size.width,
|
||||
height: bodyBounds.size.height
|
||||
)
|
||||
_machinesController.view.frame = machinesControllerFrame
|
||||
}
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal func _handleSingleFingerTap(gestureRecognizer: UITapGestureRecognizer)
|
||||
override func viewDidAppear(animated: Bool)
|
||||
{
|
||||
let randomPercentage = Float(arc4random()) / Float(UInt32.max)
|
||||
_backgroundController.setPercentActivated(randomPercentage, animated: true)
|
||||
_headerView.beginAnimating()
|
||||
}
|
||||
|
||||
internal func _handleDoubleFingerTap(gestureRecognizer: UITapGestureRecognizer)
|
||||
override func viewDidDisappear(animated: Bool)
|
||||
{
|
||||
_backgroundController.setPercentActivated(0.0, animated: true)
|
||||
_headerView.stopAnimating()
|
||||
}
|
||||
|
||||
override func prefersStatusBarHidden() -> Bool
|
||||
{
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// BackgroundViewController.swift
|
||||
// VisualizationViewController.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/29/15.
|
||||
@@ -12,9 +12,9 @@ import GLKit
|
||||
import SceneKit
|
||||
import UIKit
|
||||
|
||||
let π = Float(M_PI)
|
||||
let π = CGFloat(M_PI)
|
||||
|
||||
class BackgroundViewController: UIViewController {
|
||||
class VisualizationViewController: UIViewController {
|
||||
private var _scene: SCNScene = SCNScene()
|
||||
private var _sceneView: SCNView?
|
||||
private var _cameraNode: SCNNode = SCNNode()
|
||||
@@ -34,7 +34,6 @@ class BackgroundViewController: UIViewController {
|
||||
view.backgroundColor = UIColor.blackColor()
|
||||
view.scene = _scene
|
||||
view.allowsCameraControl = false
|
||||
view.showsStatistics = true
|
||||
|
||||
_sceneView = view
|
||||
self.view = view
|
||||
@@ -88,7 +87,7 @@ class BackgroundViewController: UIViewController {
|
||||
let ry = Float(arc4random()) / Float(UInt32.max)
|
||||
let rz = Float(arc4random()) / Float(UInt32.max)
|
||||
let rotAxis = SCNVector3Make(rx, ry, rz)
|
||||
let rotCoeff = Float(arc4random() % 2 == 0 ? -1.0 : 1.0)
|
||||
let rotCoeff = CGFloat(arc4random() % 2 == 0 ? -1.0 : 1.0)
|
||||
let rotAngle = CGFloat(rotCoeff * π / 4.0)
|
||||
|
||||
let rotAction = SCNAction.rotateByAngle(rotAngle, aroundAxis: rotAxis, duration: 0.8)
|
||||
@@ -108,7 +107,7 @@ class BackgroundViewController: UIViewController {
|
||||
let camera = SCNCamera()
|
||||
|
||||
_cameraNode.camera = camera
|
||||
_cameraNode.position = SCNVector3Make(0.0, 0.0, 50.0)
|
||||
_cameraNode.position = SCNVector3Make(0.0, 0.0, 30.0)
|
||||
_scene.rootNode.addChildNode(_cameraNode)
|
||||
|
||||
let centerNode = SCNNode()
|
||||
@@ -136,10 +135,10 @@ class BackgroundViewController: UIViewController {
|
||||
{
|
||||
_cublets.removeAll()
|
||||
|
||||
let sz = Float(BackgroundViewController.cubletsSize)
|
||||
let dim = BackgroundViewController.cubletsDimensions
|
||||
let sz = Float(VisualizationViewController.cubletsSize)
|
||||
let dim = VisualizationViewController.cubletsDimensions
|
||||
let dimf = Float(dim)
|
||||
let spacing = Float(BackgroundViewController.cubletsSpacing)
|
||||
let spacing = Float(VisualizationViewController.cubletsSpacing)
|
||||
let volume = (dimf * sz) + ((dimf - 1.0) * spacing)
|
||||
let orig = -volume / 2.0
|
||||
|
||||
@@ -177,7 +176,7 @@ class BackgroundViewController: UIViewController {
|
||||
internal func _setupAnimation()
|
||||
{
|
||||
let rotAxis = SCNVector3Make(0.25, 1.75, 1.0)
|
||||
let rotAngle = CGFloat(Float(2.0) * π)
|
||||
let rotAngle = 2.0 * π
|
||||
let rotAction = SCNAction.repeatActionForever(SCNAction.rotateByAngle(rotAngle, aroundAxis: rotAxis, duration: 40.0))
|
||||
_cubletsNode.runAction(rotAction)
|
||||
}
|
||||
Reference in New Issue
Block a user