Commit 480ab7cc authored by toby's avatar toby

appState

parent 82bb94fe
......@@ -14,6 +14,11 @@ struct BGTransition {
let endColor: UIColor
}
struct AppState {
var paused: Bool = false
var animating: Bool = false
}
func degreesToRadians(degrees: CGFloat) -> CGFloat {
return degrees * (3.1415926 / 180)
}
......@@ -47,8 +52,7 @@ class ViewController: UIViewController {
var backgroundTransition: BGTransition!
var paused = false
var animating = false
var appState = AppState()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -93,9 +97,9 @@ class ViewController: UIViewController {
switch hold.state {
case UIGestureRecognizerState.Began:
println("started bro")
self.animating = true
self.appState.animating = true
if(!paused) {
if(!self.appState.paused) {
println("not paused")
UIView.animateWithDuration(
self.backgroundTransition.duration,
......@@ -107,8 +111,8 @@ class ViewController: UIViewController {
completion: {
(finished: Bool) -> Void in
println("done animating bro")
self.paused = false
self.animating = false
self.appState.paused = false
self.appState.animating = false
UIView.animateWithDuration(
0.25,
delay: 0.0,
......@@ -135,20 +139,19 @@ class ViewController: UIViewController {
})
} else {
println("paused")
paused = false
self.appState.paused = false
let pausedTime = self.view!.layer.timeOffset
self.view!.layer.speed = 1
self.view!.layer.timeOffset = 0.0
self.view!.layer.beginTime = 0.0
let timeSincePause = self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
self.view!.layer.beginTime = timeSincePause
}
case UIGestureRecognizerState.Ended:
println("ended bro \(self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil))")
if(animating == true) {
paused = true
animating = false
if(self.appState.animating == true) {
self.appState.paused = true
self.appState.animating = false
let pausedTime = self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
self.view!.layer.speed = 0
self.view!.layer.timeOffset = pausedTime
......
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