Commit df9a56f7 authored by toby's avatar toby

simple block removal animation

parent 366b41cd
......@@ -105,8 +105,8 @@ class ViewController: UIViewController {
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {
switch(motion) {
case (.MotionShake):
barriers.map({barrier in barrier.animateBackground(randomColor(), duration: 0.2)})
blocks.map(removeBlock)
barriers.map({barrier in barrier.animateBackground(randomColor(), duration: 0.5)})
default:
break
}
......@@ -152,9 +152,20 @@ class ViewController: UIViewController {
}
private func removeBlock(block: UIView) {
block.removeFromSuperview()
gravity.removeItem(block)
collision.removeItem(block)
UIView.animateWithDuration(
0.2,
delay: 0.0,
options: UIViewAnimationOptions.CurveLinear,
animations: {
block.bounds.size.width = block.bounds.size.width + (block.bounds.size.width * 0.1)
block.bounds.size.height = block.bounds.size.height + (block.bounds.size.height * 0.1)
},
completion: {
(finished: Bool) -> Void in
block.removeFromSuperview()
self.gravity.removeItem(block)
self.collision.removeItem(block)
})
}
@IBAction func backgroundHeld(hold: UILongPressGestureRecognizer) {
......@@ -172,7 +183,7 @@ class ViewController: UIViewController {
@IBAction func newBlock(sender: AnyObject) {
let location = sender.locationInView(view)
let block = UIView(frame: CGRect(x: location.x, y: location.y, width: 60, height: 60))
var block = UIView(frame: CGRect(x: location.x, y: location.y, width: 60, height: 60))
block.center = location
block.backgroundColor = UIColor.init(red: randomPercent(), green: randomPercent(), blue: randomPercent(), alpha: 1)
view.addSubview(block)
......@@ -188,5 +199,4 @@ class ViewController: UIViewController {
removeBlock(recognizer.view!)
}
}
\ 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