Commit 6fb38efa authored by toby's avatar toby

continuous animation

parent d356aadc
......@@ -54,8 +54,6 @@ class ViewController: UIViewController {
let hold = UILongPressGestureRecognizer(target: self, action: Selector("backgroundHeld:"))
view.addGestureRecognizer(hold)
let swipe = UISwipeGestureRecognizer(target: self, action: Selector("swiped:"))
view.addGestureRecognizer(swipe)
}
override func didReceiveMemoryWarning() {
......@@ -63,62 +61,64 @@ class ViewController: UIViewController {
// Dispose of any resources that can be recreated.
}
@IBAction func swiped(swipe: UISwipeGestureRecognizer) {
self.backgroundTransition = randomTransition()
}
@IBAction func backgroundHeld(hold: UILongPressGestureRecognizer) {
switch hold.state {
case UIGestureRecognizerState.Began:
println("started bro")
self.appState.animating = true
func animateBackground() -> Void {
self.appState.animating = true
UIView.animateWithDuration(
self.backgroundTransition.duration,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.endColor
},
completion: {
(finished: Bool) -> Void in
self.appState.paused = false
self.appState.animating = false
self.backgroundTransition = randomTransition()
if(!self.appState.paused) {
println("not paused")
UIView.animateWithDuration(
self.backgroundTransition.duration,
0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.endColor
self.view!.backgroundColor = UIColor.whiteColor()
},
completion: {
(finished: Bool) -> Void in
println("done animating bro")
self.appState.paused = false
self.appState.animating = false
UIView.animateWithDuration(
0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = UIColor.whiteColor()
self.view!.backgroundColor = self.backgroundTransition.startColor
},
completion: {
(finished: Bool) -> Void in
if(!self.appState.paused) {
self.animateBackground()
}
})
}
)
})
}
UIView.animateWithDuration(
0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.startColor
},
completion: nil)
}
)
})
@IBAction func backgroundHeld(hold: UILongPressGestureRecognizer) {
switch hold.state {
case UIGestureRecognizerState.Began:
if(!self.appState.paused){
self.animateBackground()
} else {
println("paused")
self.appState.animating = true
self.appState.paused = false
self.view.unpause()
}
case UIGestureRecognizerState.Ended:
println("ended bro \(self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil))")
if(self.appState.animating == true) {
self.appState.paused = true
self.appState.animating = false
......@@ -126,8 +126,7 @@ class ViewController: UIViewController {
}
default:
// println("fuck you bro" )
()
break
}
}
......
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