Commit 500399a0 authored by toby's avatar toby

use separate view for background

parent 7ad6d180
......@@ -32,9 +32,9 @@ extension ViewController: StateMachineDelegate {
case (.Ready, .Animating), (.Finished, .Animating):
animateBackground()
case (.Animating, .Paused):
view.pause()
background.pause()
case (.Paused, .Animating), (.Paused, .Finished):
view.unpause()
background.unpause()
case (.Animating, .Finished):
machine.state = .Animating
default:
......@@ -50,6 +50,7 @@ class ViewController: UIViewController {
var collision: UICollisionBehavior!
var machine: StateMachine<ViewController>!
var background: UIView!
var backgroundTransition: BGTransition!
var barriers: [UIView] = [UIView]()
......@@ -57,9 +58,13 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Setup background transition
// Setup background
background = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
background.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
backgroundTransition = randomTransition()
view.backgroundColor = backgroundTransition.startColor
background.backgroundColor = backgroundTransition.startColor
view.addSubview(background)
background.center = background.superview!.center
// Setup barrier
let barrier = UIView(frame: CGRectFromOrigin(view, 0, 40, 130, 20))
......@@ -108,7 +113,7 @@ class ViewController: UIViewController {
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.endColor
self.background!.backgroundColor = self.backgroundTransition.endColor
},
completion: {
(finished: Bool) -> Void in
......@@ -117,7 +122,7 @@ class ViewController: UIViewController {
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = UIColor.whiteColor()
self.background!.backgroundColor = UIColor.whiteColor()
},
completion: {
......@@ -128,7 +133,7 @@ class ViewController: UIViewController {
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.startColor
self.background!.backgroundColor = self.backgroundTransition.startColor
},
completion: {
......@@ -156,9 +161,7 @@ class ViewController: UIViewController {
@IBAction func newBlock(sender: AnyObject) {
let location = sender.locationInView(view)
let block: UIView
block = UIView(frame: CGRect(x: location.x, y: location.y, width: 60, height: 60))
let 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)
......@@ -176,5 +179,4 @@ class ViewController: UIViewController {
}
}
}
\ 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