Commit 061140da authored by toby's avatar toby

remove boxes on tap

parent 06df484e
......@@ -26,12 +26,12 @@ class ViewController: UIViewController {
var animator: UIDynamicAnimator!
var gravity: UIGravityBehavior!
var collision: UICollisionBehavior!
var touch: UIPanGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
let barrier = UIView(frame: CGRect(x: 0, y: 300, width: 130, height: 20))
let barrier = UIView(frame: CGRectFromOrigin(view, 0, 40, 130, 20))
barrier.backgroundColor = UIColor.redColor()
view.addSubview(barrier)
......@@ -56,14 +56,27 @@ class ViewController: UIViewController {
@IBAction func newBlock(sender : AnyObject) {
let location = sender.locationInView(view)
var block: UIView
block = UIView(frame: CGRect(x: location.x, y: location.y, width: 10, height: 10))
let block: UIView
block = UIView(frame: CGRect(x: location.x, y: location.y, width: 60, height: 60))
block.center = location
block.backgroundColor = UIColor.init(red: randPercent(), green: randPercent(), blue: randPercent(), alpha: 1)
view.addSubview(block)
gravity.addItem(block)
collision.addItem(block)
let touch = UITapGestureRecognizer(target: self, action: Selector("blockTouch:"))
block.addGestureRecognizer(touch)
}
@IBAction func blockTouch(recognizer: UIGestureRecognizer) {
println("block touched!")
recognizer.view!.removeFromSuperview()
gravity.removeItem(recognizer.view!)
collision.removeItem(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