Commit b36d3ff4 authored by toby's avatar toby

don't create gesture recognizer for each block

parent 277b5ef2
......@@ -49,15 +49,13 @@ extension ViewController: StateMachineDelegate {
background.unpause()
case (.AnimatingBackground, .Finished):
machine.state = .AnimatingBackground
case ((let origin), .AddBlock(let block)):
case ((let originState), .AddBlock(let block)):
view.addSubview(block)
gravity.addItem(block)
collision.addItem(block)
let tap = UITapGestureRecognizer(target: self, action: Selector("blockTouch:"))
block.addGestureRecognizer(tap)
blocks.append(block)
machine.state = origin
machine.state = originState
default:
break
}
......@@ -77,6 +75,9 @@ class ViewController: UIViewController {
var blocks: [UIView] = [UIView]()
var barriers: [UIView] = [UIView]()
var tap: UITapGestureRecognizer!
var hold: UILongPressGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
......@@ -110,7 +111,8 @@ class ViewController: UIViewController {
animator.addBehavior(collision)
// Setup gestures
let hold = UILongPressGestureRecognizer(target: self, action: Selector("backgroundHeld:"))
tap = UITapGestureRecognizer(target: self, action: Selector("blockTouch:"))
hold = UILongPressGestureRecognizer(target: self, action: Selector("backgroundHeld:"))
view.addGestureRecognizer(hold)
// Setup state machine
......
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