Commit 366b41cd authored by toby's avatar toby

track blocks, remove on shake

parent 500399a0
......@@ -28,7 +28,7 @@ extension ViewController: StateMachineDelegate {
typealias StateType = BackgroundState
func didTransitionFrom(from: StateType, to: StateType) {
switch (from, to){
switch (from, to) {
case (.Ready, .Animating), (.Finished, .Animating):
animateBackground()
case (.Animating, .Paused):
......@@ -53,6 +53,7 @@ class ViewController: UIViewController {
var background: UIView!
var backgroundTransition: BGTransition!
var blocks: [UIView] = [UIView]()
var barriers: [UIView] = [UIView]()
override func viewDidLoad() {
......@@ -102,8 +103,12 @@ class ViewController: UIViewController {
}
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {
if motion == .MotionShake {
switch(motion) {
case (.MotionShake):
barriers.map({barrier in barrier.animateBackground(randomColor(), duration: 0.2)})
blocks.map(removeBlock)
default:
break
}
}
......@@ -146,6 +151,12 @@ class ViewController: UIViewController {
})
}
private func removeBlock(block: UIView) {
block.removeFromSuperview()
gravity.removeItem(block)
collision.removeItem(block)
}
@IBAction func backgroundHeld(hold: UILongPressGestureRecognizer) {
switch hold.state {
case UIGestureRecognizerState.Began:
......@@ -170,12 +181,11 @@ class ViewController: UIViewController {
let tap = UITapGestureRecognizer(target: self, action: Selector("blockTouch:"))
block.addGestureRecognizer(tap)
blocks.append(block)
}
@IBAction func blockTouch(recognizer: UIGestureRecognizer) {
recognizer.view!.removeFromSuperview()
gravity.removeItem(recognizer.view!)
collision.removeItem(recognizer.view!)
removeBlock(recognizer.view!)
}
......
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