Commit e3cbae5e authored by toby's avatar toby

flip button, programmatically display view

parent d0f254c1
......@@ -50,8 +50,8 @@ func degreesToRadians(degrees: CGFloat) -> CGFloat {
}
func CGRectFromOrigin(view: UIView, xPercent: CGFloat, yPercent: CGFloat, width: CGFloat, height: CGFloat) -> CGRect {
let y = view.bounds.size.height * (yPercent / 100)
let x = view.bounds.size.width * (xPercent / 100)
let y = view.bounds.size.height * (yPercent / 100)
return CGRect(x: x, y: y, width: width, height: height)
}
......
......@@ -8,13 +8,13 @@
/* Begin PBXBuildFile section */
DA376F0D1AAD1C4B0071423A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA376F0C1AAD1C4B0071423A /* AppDelegate.swift */; };
DA376F0F1AAD1C4B0071423A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA376F0E1AAD1C4B0071423A /* ViewController.swift */; };
DA376F121AAD1C4B0071423A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DA376F101AAD1C4B0071423A /* Main.storyboard */; };
DA376F0F1AAD1C4B0071423A /* WorldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA376F0E1AAD1C4B0071423A /* WorldViewController.swift */; };
DA376F141AAD1C4B0071423A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DA376F131AAD1C4B0071423A /* Images.xcassets */; };
DA376F171AAD1C4B0071423A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = DA376F151AAD1C4B0071423A /* LaunchScreen.xib */; };
DA376F231AAD1C4B0071423A /* loboTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA376F221AAD1C4B0071423A /* loboTests.swift */; };
DA6CF1091ABF865500270C05 /* StateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6CF1081ABF865500270C05 /* StateMachine.swift */; };
DAAE8A531ABE313400DDFA37 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAAE8A521ABE313400DDFA37 /* Utils.swift */; };
DAFF0D101AE3270000ADC4BF /* ColorDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAFF0D0F1AE3270000ADC4BF /* ColorDetailViewController.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -31,8 +31,7 @@
DA376F071AAD1C4B0071423A /* lobo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = lobo.app; sourceTree = BUILT_PRODUCTS_DIR; };
DA376F0B1AAD1C4B0071423A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DA376F0C1AAD1C4B0071423A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
DA376F0E1AAD1C4B0071423A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
DA376F111AAD1C4B0071423A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
DA376F0E1AAD1C4B0071423A /* WorldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorldViewController.swift; sourceTree = "<group>"; };
DA376F131AAD1C4B0071423A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
DA376F161AAD1C4B0071423A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
DA376F1C1AAD1C4B0071423A /* loboTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = loboTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -40,6 +39,7 @@
DA376F221AAD1C4B0071423A /* loboTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = loboTests.swift; sourceTree = "<group>"; };
DA6CF1081ABF865500270C05 /* StateMachine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateMachine.swift; sourceTree = "<group>"; };
DAAE8A521ABE313400DDFA37 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Utils.swift; path = ../Utils.swift; sourceTree = "<group>"; };
DAFF0D0F1AE3270000ADC4BF /* ColorDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorDetailViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -84,8 +84,8 @@
DA376F0C1AAD1C4B0071423A /* AppDelegate.swift */,
DA6CF1081ABF865500270C05 /* StateMachine.swift */,
DAAE8A521ABE313400DDFA37 /* Utils.swift */,
DA376F0E1AAD1C4B0071423A /* ViewController.swift */,
DA376F101AAD1C4B0071423A /* Main.storyboard */,
DA376F0E1AAD1C4B0071423A /* WorldViewController.swift */,
DAFF0D0F1AE3270000ADC4BF /* ColorDetailViewController.swift */,
DA376F131AAD1C4B0071423A /* Images.xcassets */,
DA376F151AAD1C4B0071423A /* LaunchScreen.xib */,
DA376F0A1AAD1C4B0071423A /* Supporting Files */,
......@@ -199,7 +199,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DA376F121AAD1C4B0071423A /* Main.storyboard in Resources */,
DA376F171AAD1C4B0071423A /* LaunchScreen.xib in Resources */,
DA376F141AAD1C4B0071423A /* Images.xcassets in Resources */,
);
......@@ -219,9 +218,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DA376F0F1AAD1C4B0071423A /* ViewController.swift in Sources */,
DA376F0F1AAD1C4B0071423A /* WorldViewController.swift in Sources */,
DA376F0D1AAD1C4B0071423A /* AppDelegate.swift in Sources */,
DAAE8A531ABE313400DDFA37 /* Utils.swift in Sources */,
DAFF0D101AE3270000ADC4BF /* ColorDetailViewController.swift in Sources */,
DA6CF1091ABF865500270C05 /* StateMachine.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -245,14 +245,6 @@
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
DA376F101AAD1C4B0071423A /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
DA376F111AAD1C4B0071423A /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
DA376F151AAD1C4B0071423A /* LaunchScreen.xib */ = {
isa = PBXVariantGroup;
children = (
......
......@@ -15,7 +15,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let worldViewController = WorldViewController()
let navigationController = UINavigationController(rootViewController: worldViewController)
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = navigationController
window!.makeKeyAndVisible()
return true
}
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7519.1" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7513.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="lobo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<gestureRecognizers/>
<connections>
<outletCollection property="gestureRecognizers" destination="7L0-Kf-cEf" appends="YES" id="Wnl-XV-H0v"/>
</connections>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
<tapGestureRecognizer id="7L0-Kf-cEf">
<connections>
<action selector="newBlock:" destination="vXZ-lx-hvc" id="taC-4x-aCe"/>
</connections>
</tapGestureRecognizer>
</objects>
</scene>
</scenes>
</document>
//
// ColorDetailViewController.swift
// lobo
//
// Created by Toby Padilla on 4/18/15.
// Copyright (c) 2015 Toby Padilla. All rights reserved.
//
import UIKit
class ColorDetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.redColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@
<key>UILaunchStoryboardName</key>
<string>Main</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<string></string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
......
......@@ -10,11 +10,21 @@ import UIKit
enum BackgroundState:StateMachineDataSource{
case Ready, AnimatingBackground, AddBlock(UIView), RemoveBlock(UIView), PausedBackground, Finished
case Ready, AnimatingBackground, AddBlock(UIView), RemoveBlock(UIView), PausedBackground, PresentColorDetail, Finished
func shouldTransitionFrom(from:BackgroundState, to: BackgroundState) -> Should {
switch (from, to){
case (.Ready, .AnimatingBackground), (.PausedBackground, .AnimatingBackground), (.AnimatingBackground, .PausedBackground), (.AnimatingBackground, .Finished), (.PausedBackground, .Finished), (.Finished, .AnimatingBackground):
case (.Ready, .AnimatingBackground):
return .Continue
case (.PausedBackground, .AnimatingBackground):
return .Continue
case (.AnimatingBackground, .PausedBackground):
return .Continue
case (.AnimatingBackground, .Finished):
return .Continue
case (.PausedBackground, .Finished):
return .Continue
case (.Finished, .AnimatingBackground):
return .Continue
case(_, .RemoveBlock(let block)):
return .Continue
......@@ -32,6 +42,8 @@ enum BackgroundState:StateMachineDataSource{
return .Continue
case(.AddBlock(let block), .PausedBackground):
return .Continue
case(_, .PresentColorDetail):
return .Continue
default:
return .Abort
}
......@@ -39,7 +51,7 @@ enum BackgroundState:StateMachineDataSource{
}
extension ViewController: StateMachineDelegate {
extension WorldViewController: StateMachineDelegate {
typealias StateType = BackgroundState
......@@ -59,6 +71,8 @@ extension ViewController: StateMachineDelegate {
case ((let originState), .AddBlock(let block)):
addBlock(block)
machine.state = originState
case (_, .PresentColorDetail):
println("segue color detail")
default:
break
}
......@@ -66,23 +80,32 @@ extension ViewController: StateMachineDelegate {
}
class ViewController: UIViewController {
class WorldViewController: UIViewController {
var animator: UIDynamicAnimator!
var gravity: UIGravityBehavior!
var collision: UICollisionBehavior!
var machine: StateMachine<ViewController>!
var machine: StateMachine<WorldViewController>!
var autoViews = [String: UIView]()
var background: UIView!
var backgroundTransition: BGTransition!
var blocks: [UIView] = [UIView]()
var barriers: [UIView] = [UIView]()
var flipButton: UIButton!
var hold: UILongPressGestureRecognizer!
var tap: UITapGestureRecognizer!
override func viewWillAppear(animated: Bool) {
navigationController!.setNavigationBarHidden(true, animated: false)
}
override func viewDidLoad() {
super.viewDidLoad()
autoViews["main"] = view
// Setup background
background = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
background.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
......@@ -97,6 +120,20 @@ class ViewController: UIViewController {
view.addSubview(barrier)
barriers.append(barrier)
// Setup flip mode
flipButton = UIButton()
flipButton.addTarget(self, action: "flipIt:", forControlEvents: .TouchUpInside)
flipButton.setTitle("Ѻ", forState: .Normal)
flipButton.backgroundColor = UIColor.clearColor()
flipButton.setTranslatesAutoresizingMaskIntoConstraints(false)
autoViews["flipButton"] = flipButton!
view.addSubview(flipButton)
let vAuthButtonConstraint = NSLayoutConstraint.constraintsWithVisualFormat("V:[flipButton(50)]-0-|", options: .AlignAllTop, metrics: nil, views: autoViews)
let hAuthButtonConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:[flipButton(50)]-0-|", options: .AlignAllTop, metrics: nil, views: autoViews)
view.addConstraints(vAuthButtonConstraint)
view.addConstraints(hAuthButtonConstraint)
// Setup gravity
gravity = UIGravityBehavior()
gravity.angle = degreesToRadians(90)
......@@ -115,6 +152,9 @@ class ViewController: UIViewController {
// Setup gestures
hold = UILongPressGestureRecognizer(target: self, action: Selector("backgroundHeld:"))
view.addGestureRecognizer(hold)
tap = UITapGestureRecognizer(target: self, action: Selector("newBlock:"))
view.addGestureRecognizer(tap)
// Setup state machine
machine = StateMachine(initialState: .Ready, delegate: self)
......@@ -240,4 +280,8 @@ class ViewController: UIViewController {
machine.state = .RemoveBlock(recognizer.view!)
}
@IBAction func flipIt(sender: AnyObject) {
machine.state = .PresentColorDetail
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment